What it does
AudioPlayer wraps an HTML5 `<audio>` element and surfaces its state through React context. Sub-components (`AudioPlayerProgress`, `AudioPlayerTime`, `AudioPlayerVolume`) auto-connect to that context — no prop drilling needed.
The `useAudioPlayer()` hook lets you attach controls to buttons placed anywhere inside the `<AudioPlayer>` tree.
Composition and API
All visual variants live in the `appearance` prop. Combine with `size` (sm/md/lg) and `shape` (flat/rounded/pill) to match your layout.
For headless usage, wrap your custom UI in `<AudioPlayer src="...">` and drive it entirely through `useAudioPlayer()`.
Common use cases
- Embed podcast or voice note playback in article pages.
- Add music preview controls to a streaming catalog.
- Build custom waveform players over the hook controls.
- Drive keyboard-accessible scrubbing via the progress bar component.
Accessibility
The progress slider carries `role="slider"`, `aria-valuenow`, `aria-valuemin`, and `aria-valuemax`. Arrow keys scrub 1 % per step; Home and End jump to the start and end.
Volume has the same slider semantics. The mute toggle button carries a descriptive `aria-label` that updates with state.
Next.js integration notes
All sub-components carry `"use client"` through the entry point, so they are safe to import from server components. Set `NEXT_PUBLIC_SITE_URL` for correct canonical and OG URLs on deploy.
FAQ
Can I wire external buttons to the player?
Yes — call `useAudioPlayer()` inside any child of `<AudioPlayer>` to get `play`, `pause`, `toggle`, and `reset` actions and attach them to any element.
Does it work with Next.js App Router?
Yes. The component uses a `"use client"` directive internally, so you can import it directly inside server components — Next.js will handle the client boundary automatically.
Is the progress bar keyboard-accessible?
Yes. `AudioPlayerProgress` carries `role="slider"` with arrow-key scrubbing (1 % per step), Home/End for extremes, and a visible focus ring.