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
| Parameter | Type | Description |
|---|---|---|
player | Player | The player instance driven by this playlist. |
Returns
Playlist
Methods
addEventListener()
addEventListener(
type,callback):void
Adds a listener for a playlist event.
Parameters
| Parameter | Type |
|---|---|
type | PlaylistEventType |
callback | PlaylistEventCallback |
Returns
void
append()
append(
item):Promise<void>
Adds an item at the end of the playlist.
Parameters
| Parameter | Type |
|---|---|
item | PlayerConfiguration |
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
| Parameter | Type | Default value | Description |
|---|---|---|---|
position | number | undefined | The index of the playlist item. |
reload | boolean | false | Force 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
| Parameter | Type | Description |
|---|---|---|
item | PlayerConfiguration | The new playlist item. |
index | number | The 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
| Parameter | Type | Description |
|---|---|---|
index | number | The 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
| Parameter | Type |
|---|---|
type | PlaylistEventType |
callback | PlaylistEventCallback |
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>