AudioPlayerProvider
Keep an audio session across page changes.
Text and Markdown example
1function Example() {
2 function Controls() {
3 const { close } = useAudioPlayer();
4 return <Button variant="outline" onClick={close}>Close audio session</Button>;
5 }
6 return <AudioPlayerProvider><Controls /></AudioPlayerProvider>;
7}How to use it
Mount it in a persistent layout. useAudioPlayer returns play and close to control the session from descendants.
To start audio, call play({ id: "track", src: "/audio.mp3", type: "audio", title: "My track" }) with an existing file. The provider must sit above pages that share playback.
Import
1import { AudioPlayerProvider } from "@kivora/nextjs";Interactive examples run inside a component with "use client". The playground's Copy button includes the imports needed for the current example.
API reference 0.2.0
Types from the installed published version, including component properties and common HTML attributes. “Optional” does not imply a default value; omitting a property lets the component decide.
| Property | Type | Description |
|---|---|---|
activeQueueId | string | Configures activeQueueId. The type describes the supported values and structure. |
aria-label | string | Accessible name of the control. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
controlsVariant | "standard" | "compact" | "cinema" | "series" | Presentation of player controls. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
id | string | Element identifier; associates labels and descriptions. |
locale | string | Localization in the format expected by the component. |
messages | Partial<{ play: string; pause: string; seek: string; volume: string; mute: string; unmute: string; fullscreen: string; exitFullscreen: string; pip: string; settings: string; quality: string; audio: string; subtitles: string; speed: string; auto: string; off: string; live: string; goLive: string; loading: string; splash: string; ad: string; containsAds: string; skipAd: string; error: string; retry: string; download: string; cancelDownload: string; downloads: string; remove: string; playOffline: string; downloading: string; close: string; expand: string; collapse: string; exportFile: string; emptyDownloads: string; expired: string; back: string; forward: string; downloadError: string; actionError: string; upNext: string; nowPlaying: string; episodes: string; previous: string; next: string; }> | Localized messages replacing the defaults. |
muted | boolean | Start or keep playback muted. |
onChange | ChangeEventHandler<HTMLDivElement, Element> | Change event. Check the type: some controls return an object, others a DOM event. |
onClick | MouseEventHandler<HTMLDivElement> | Action performed when the element is activated. |
onQueueSelect | ((item: PlayerQueueItem) => void) | Callback for this event. The signature describes its arguments. |
onSubmit | SubmitEventHandler<HTMLDivElement> | Form submission event. |
options | PlayerControllerOptions | Component options or configuration. See the type structure. |
overlays | PlayerOverlay[] | Configures overlays. The type describes the supported values and structure. |
presentation | "footer" | "inline" | "sheet" | Audio players can live in the footer and expand into a bottom sheet. |
program | PlayerProgram | Configures program. The type describes the supported values and structure. |
queue | PlayerQueueItem[] | Configures queue. The type describes the supported values and structure. |
role | AriaRole | Semantic role of the element. Keep the default role unless a change is justified. |
settingsLayout | "list" | "tabs" | Mobile settings presentation; list preserves the previous layout. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
title | string | Title or supplementary information. |
TypeScript definition
Review each component's properties and published declaration. Native and accessibility attributes are inherited from the element specified by its type.
AudioPlayerProvider25 properties
1declare function AudioPlayerProvider({ children, ...props }: React.PropsWithChildren<Omit<PlayerProps, 'source' | 'controller' | 'autoPlay'>>): React.JSX.Element;