Skip to main content

Playlist

Enables sequential playback of multiple media items over a single Player.

Each item is a PlayerConfiguration (its metaData carries the title, artwork, etc.). This is a thin wrapper over the native playlist bridge (Android: SingleControllerPlaylist); the queue and its transitions are managed natively and this class caches state fed back through events.

Constructing a Playlist requests that its player is created with playlist support, so it must be created synchronously after the Player (before player.ready resolves) — which the PlaylistProvider guarantees.

Limitations: clear and DRM-protected items cannot be mixed in the same playlist, and on iOS only HLS items are supported — Playlist.append and Playlist.insert throw a PrestoPlayError when an item violates either constraint.

Constructors​

new Playlist()​

new Playlist(player): Playlist

Parameters​

ParameterTypeDescription
playerPlayerThe player instance driven by this playlist.

Returns​

Playlist

Methods​

addEventListener()​

addEventListener(type, callback): void

Adds a listener for a playlist event.

Parameters​

ParameterType
typePlaylistEventType
callbackPlaylistEventCallback

Returns​

void


append()​

append(item): Promise<void>

Adds an item at the end of the playlist.

Parameters​

ParameterType
itemPlayerConfiguration

Returns​

Promise<void>

Throws​

A PrestoPlayError with code ErrorCode.PlaylistMixedContent when mixing clear and DRM-protected items, or with code ErrorCode.PlaylistUnsupportedContent for non-HLS items on iOS (see Playlist limitations).


clear()​

clear(): Promise<void>

Removes all playlist items and stops iterating.

Returns​

Promise<void>


destroy()​

destroy(): Promise<void>

Destroys the playlist: detaches it from the player natively and removes all listeners. The player itself is not destroyed. Called by the PlaylistProvider on unmount; a destroyed playlist must not be used.

Returns​

Promise<void>


getCurrent()​

getCurrent(): null | PlayerConfiguration

Returns the current item, or null if the playlist is empty.

Returns​

null | PlayerConfiguration


getPosition()​

getPosition(): number

Returns the position (index) of the current playlist item.

Returns​

number


getQueue()​

getQueue(): PlayerConfiguration[]

Returns the internal list of playlist items.

Returns​

PlayerConfiguration[]


getUpcoming()​

getUpcoming(): null | PlayerConfiguration

Returns the upcoming item, or null at the end of the playlist.

Returns​

null | PlayerConfiguration


goTo()​

goTo(position, reload): Promise<void>

Goes to a specific playlist item. Before Playlist.start it selects the item the playlist will start at. Out-of-range positions are ignored.

Parameters​

ParameterTypeDefault valueDescription
positionnumberundefinedThe index of the playlist item.
reloadbooleanfalseForce a reload even if already at position. Default false.

Returns​

Promise<void>


insert()​

insert(item, index): Promise<void>

Inserts an item at the given index, keeping the current item selected.

Parameters​

ParameterTypeDescription
itemPlayerConfigurationThe new playlist item.
indexnumberThe index where the item is inserted.

Returns​

Promise<void>

Throws​

A PrestoPlayError with code ErrorCode.PlaylistMixedContent when mixing clear and DRM-protected items, or with code ErrorCode.PlaylistUnsupportedContent for non-HLS items on iOS (see Playlist limitations).


isStarted()​

isStarted(): boolean

Returns whether the playlist is currently iterating.

Returns​

boolean


next()​

next(): Promise<void>

Goes to the next playlist item.

Returns​

Promise<void>


previous()​

previous(): Promise<void>

Goes to the previous playlist item.

Returns​

Promise<void>


remove()​

remove(index): Promise<void>

Removes an item from the playlist.

Parameters​

ParameterTypeDescription
indexnumberThe index of the playlist item.

Returns​

Promise<void>

Throws​

When attempting to remove the current item.


removeEventListener()​

removeEventListener(type, callback): void

Removes a previously added playlist event listener.

Parameters​

ParameterType
typePlaylistEventType
callbackPlaylistEventCallback

Returns​

void


start()​

start(): Promise<void>

Begins iterating the playlist by opening the queue at the current item.

Returns​

Promise<void>


stop()​

stop(): Promise<void>

Stops iterating the playlist. Does not stop playback.

Returns​

Promise<void>