Reference / @open-music-sdk/lib-preview-player / tPreviewPlayer
Interface: tPreviewPlayer<T>
Defined in: lib/lib-preview-player/src/player.ts:138
A player from previewPlayer. Its functions need no this, so each can be handed on by itself. It is disposable with await using where the runtime has that: in one that has no Symbol.asyncDispose, a player has no such function, and dispose() is the way.
Extends
AsyncDisposable
Type Parameters
T
T extends tPreviewable = tPreviewable
Properties
dispose
readonly dispose: () => void;Defined in: lib/lib-preview-player/src/player.ts:230
Pauses, takes its clip off the element and lets go of it, forgets the queue and whoever listens. The element is yours again, to reuse or drop. Afterwards every other function refuses, and calling this again does nothing.
Returns
void
Throws
What a listener threw on hearing of the last change. The listeners are let go of all the same.
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.
next
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.
pause
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.
play
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.
previous
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.
seek
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.
setVolume
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.
state
readonly state: tPreviewPlayerState<T>;Defined in: lib/lib-preview-player/src/player.ts:208
Where the player stands now. The same object for as long as nothing changes.
subscribe
readonly subscribe: (listener) => () => void;Defined in: lib/lib-preview-player/src/player.ts:223
Calls listener after each change of state, and gives the function that stops it. A listener subscribed twice is called twice, and each of its two is stopped alone. While a clip plays, position changes as often as the element says so, several times a second.
A listener may call the player back. The element is asked to play before anyone hears that a clip is loading, so a listener that pauses, loads another queue or disposes on hearing it has the last word. Every listener is called, whatever another throws: the player's own work is done first, and the first error is then thrown on, to whoever called the function, or out through the element's event when it was the element that spoke.
Parameters
listener
() => void
What to call after each change. It takes nothing: the state is read from state.
Returns
The function that stops the calls. It can be called more than once, and throws nothing.
() => void
Throws
TypeError if the player was disposed, or if listener is no function.
Methods
[asyncDispose]()
[asyncDispose](): PromiseLike<void>;Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.disposable.d.ts:38
Returns
PromiseLike<void>
Inherited from
AsyncDisposable.[asyncDispose]