The playlist is an array-like object.
It exposes indexed elements (accessible via bracket notation), a playlist.length property and a playlist.push method.
Every element in the playlist array is a Node instance, to be played in sequence by the player.
Example
const player = new InterludePlayer('#playerContainer');
// ...
player.playlist.push('node_myNodeId');
// ...
for (let i = 0; i < player.playlist.length; i++) {
console.log(player.playlist[i].id);
}
- Table of Contents
- Properties
- lengthpro
- Methods
- Properties
Properties
player.playlist.length : number
The length property specifies the number of node elements in the playlist array.
Example
player.playlist.push('node1');
console.log(player.playlist.length); // 1
Methods
player.playlist.push() ⇒ number
Push a node (or nodes) into the playlist array.
Accepts one or more arguments, every argument should either be a string (node id) or object (node instance).
Returns: number
- The new length of playlist array
See: playlistpush
Param | Type | Description |
---|---|---|
…node | string | Node |
A node id (of a node that exists in repository), or a node object. |
Example
// Pushing two nodes into the playlist (using node IDs):
player.playlist.push('node1', 'node2');
// Pushing a node into the playlist using node object:
const nodeObj = player.repository.get('node1');
player.playlist.push(nodeObj);
player.playlist.reset()
Clears all nodes from the playlist array (does not affect nodes in repository).
A side effect of calling this method, is that playback will be stopped (if currently playing).
See: playlistreset
Example
player.playlist.reset();
console.log(player.playlist.length); // 0
player.playlist.timeOffsetAtIndex(index) ⇒ number
Returns the time offset (in seconds) from the beginning of playlist, to the start of a node at given index.
Returns: number
- Time in seconds, from beginning of playlist to start of node at given index.
Param | Type | Description |
---|---|---|
index | number |
An integer in the range [0, playlist.length]. |
Example
let timeInNode =
player.currentTime - player.playlist.timeOffsetAtIndex(player.currentNodeIndex);
let remainingTimeInNode = player.currentNode.duration - timeInNode;
console.log(
`We're ${timeInNode} seconds into "${player.currentNodeId}".
Still ${remainingTimeInNode} seconds to go!`
);