Reference / @open-music-sdk/react / tUsePreviewPlayer
Interface: tUsePreviewPlayer<T>
Defined in: integrations/react/src/client.ts:232
The player's verbs, each keeping its identity for as long as the component lives, and where it stands.
Extends
tVerbs<T>
Type Parameters
T
T extends tPreviewable = tPreviewable
Properties
load
readonly load: (tracks) => tLoadedPreviews<T>;Defined in: lib/lib-preview-player/src/player.ts:151
Replaces the queue with the tracks that have a clip, and answers with those and with the ones left out. What was playing stops and its clip is taken off the element, no track is current afterwards, and nothing is played.
Parameters
tracks
readonly T[]
The tracks to queue, as a client handed them over: songs or music videos of the catalog, or anything else with attributes.previews. One without a clip, or whose clip is not on an allowed host, is left out and is never an error.
Returns
The tracks that are now the queue, in the order they were handed over, and the ones left out, each with where it was and why.
Throws
TypeError if the player was disposed, or if tracks is no list.
Throws
What a listener threw on hearing of the change, after the queue has been replaced.
Inherited from
tVerbs.loadnext
readonly next: () => Promise<void>;Defined in: lib/lib-preview-player/src/player.ts:181
Plays the next track of the queue from its start. At the last one, or with nothing loaded, it does nothing.
Returns
Promise<void>
Throws
TypeError if the player was disposed.
Throws
The element's own refusal to play, as play rejects with it.
Throws
What a listener threw on hearing of the change, as play rejects with it.
Inherited from
tVerbs.nextpause
readonly pause: () => void;Defined in: lib/lib-preview-player/src/player.ts:173
Pauses the current clip. With none current it does nothing.
Returns
void
Throws
TypeError if the player was disposed.
Inherited from
tVerbs.pauseplay
readonly play: (index?) => Promise<void>;Defined in: lib/lib-preview-player/src/player.ts:167
Plays the track at index from its start. With no index, it carries on with the current clip, or starts the first track when none is current or the queue ran out, and asks again for a clip the element could not play. It settles as the element's own play() does: a browser that will not start sound without a click says so here, with its own error. With nothing loaded and no index it does nothing.
Parameters
index?
number
The place in the queue of the track to play, counted from 0, or nothing to carry on.
Returns
Promise<void>
Throws
TypeError if the player was disposed, or if index is not the place of a track in the queue.
Throws
The element's own refusal to play, as it rejected with it: a browser's NotAllowedError where it wants a click behind the sound, or its AbortError where a later call overtook this one. The state is then paused, or error where the element said why with an event, unless a later call has taken over, when the state is that call's.
Throws
What a listener threw on hearing that the clip is loading or playing. The element was asked all the same.
Inherited from
tVerbs.playprevious
readonly previous: () => Promise<void>;Defined in: lib/lib-preview-player/src/player.ts:189
Plays the track before the current one from its start. At the first one, or with none current, it does nothing.
Returns
Promise<void>
Throws
TypeError if the player was disposed.
Throws
The element's own refusal to play, as play rejects with it.
Throws
What a listener threw on hearing of the change, as play rejects with it.
Inherited from
tVerbs.previousseek
readonly seek: (seconds) => void;Defined in: lib/lib-preview-player/src/player.ts:198
Moves to seconds into the current clip. The element holds it to the clip's length. With no track current it does nothing.
Parameters
seconds
number
How far into the clip to move, from 0.
Returns
void
Throws
TypeError if the player was disposed, or if seconds is not a number from 0.
Throws
What a listener threw on hearing of the change, after the move.
Inherited from
tVerbs.seeksetVolume
readonly setVolume: (volume) => void;Defined in: lib/lib-preview-player/src/player.ts:206
Sets the element's volume.
Parameters
volume
number
How loud, from 0 to 1.
Returns
void
Throws
TypeError if the player was disposed, or if volume is not a number from 0 to 1.
Throws
What a listener threw on hearing of the change, after the volume was set.
Inherited from
tVerbs.setVolumestate
readonly state: tPreviewPlayerState<T>;Defined in: integrations/react/src/client.ts:234
Where the player stands: its own frozen snapshot, and one idle snapshot on the server and before the component mounts.