Skip to content
Client
Server

Reference / @open-music-sdk/react / usePreviewPlayer

Function: usePreviewPlayer() ​

ts
function usePreviewPlayer<T>(options?): tUsePreviewPlayer<T>;

Defined in: integrations/react/src/client.ts:254

A preview player for the component: made when it mounts, since an audio element is a browser's, and disposed when it unmounts. state is the player's own snapshot through useSyncExternalStore, and the idle one before that. The verbs keep their identity, so one can go into an effect's dependencies; one called before the player exists, which only a child's effect can do, is a TypeError. The options are read on the first mount only.

Type Parameters ​

T ​

T extends tPreviewable = tPreviewable

Parameters ​

options? ​

tUsePreviewPlayerOptions

The player's options, with the element to play through or a ref to it.

Returns ​

tUsePreviewPlayer<T>

The player's state and its verbs; each verb throws and rejects as the player's own does.

Throws ​

TypeError if audio is a ref with nothing in it when the component mounts, or previewPlayer refuses an option: thrown then, from the effect, so it reaches the nearest error boundary rather than this call.

MIT licensed. Not affiliated with, endorsed by, or sponsored by Apple Inc. Apple Music and MusicKit are trademarks of Apple Inc.