nook
Browse the docs

Components

Audio Player

Native

A player for one track: play, seek, time and mute.

See the prompt

Morning chord ยท Nook Studio

0:00 / 0:00

Installation

npx nook-ui@latest add audio-player

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Audio Player" component to this project, exactly as Nook ships it.

A player for one track: play, seek, time and mute.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add audio-player`. It writes `components/ui/audio-player.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/audio-player.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import { AudioPlayer } from "@/components/ui/audio-player";

export default function AudioPlayerDefault() {
  return (
    <AudioPlayer
      className="max-w-md"
      src="/examples/tone.m4a"
      title="Morning chord"
      artist="Nook Studio"
      cover={
        <span aria-hidden="true" className="grid size-full grid-cols-3 gap-1 bg-brand p-2.5">
          {Array.from({ length: 9 }, (_, index) => (
            <span key={index} className={index % 4 === 0 ? "bg-brand-foreground" : "bg-brand-foreground/30"} />
          ))}
        </span>
      }
    />
  );
}
```

API
- `AudioPlayer`: The player. Also accepts everything an `audio` element does, such as `src` and `loop`.
  - `title` (`string`): The track name.
  - `artist` (`string`): Who made it.
  - `cover` (`ReactNode`): A cover image or any small square element.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Drives a real audio element, so media keys work. Every control is a labelled button; the seek bar is a range input that works with the arrow keys and announces the time.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { AudioPlayer } from "@/components/ui/audio-player";

export default function AudioPlayerDefault() {
  return (
    <AudioPlayer
      className="max-w-md"
      src="/examples/tone.m4a"
      title="Morning chord"
      artist="Nook Studio"
      cover={
        <span aria-hidden="true" className="grid size-full grid-cols-3 gap-1 bg-brand p-2.5">
          {Array.from({ length: 9 }, (_, index) => (
            <span key={index} className={index % 4 === 0 ? "bg-brand-foreground" : "bg-brand-foreground/30"} />
          ))}
        </span>
      }
    />
  );
}

Examples

Voice memo

Voice memo: pricing page ideas ยท Maya Chen, today 9:12

0:00 / 0:00

Several episodes

Episode 12: Pricing without fear ยท The Small Team Show

0:00 / 0:00

Episode 11: Hiring your first designer ยท The Small Team Show

0:00 / 0:00

Long title

Episode 142: Why every migration takes twice as long as the plan says, with Dana Whitfield ยท The Shipping Log, a podcast about small teams that build software

0:00 / 0:00

Props

AudioPlayer

The player. Also accepts everything an `audio` element does, such as `src` and `loop`.

PropTypeDefaultDescription
titlestringโ€“The track name.
artiststringโ€“Who made it.
coverReactNodeโ€“A cover image or any small square element.

Accessibility

Drives a real audio element, so media keys work. Every control is a labelled button; the seek bar is a range input that works with the arrow keys and announces the time.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.