Registers a playlist item callback that can modify or block the progression of a playlist
The playlist item callback accepts two arguments, the playlist item, and its index in the playlist. There are four outcomes the callback can produce:
- Return from the callback synchronously to allow the item to load and play without changes
- Return a promise that resolves with a new or modified playlist item
- Return a promise that resolves without changes
- Return a promise that rejects to skip loading and playback of that item
jwplayer().setPlaylistItemCallback(function(item, index) {
console.log(item); // The playlist item that will be loaded
console.log(index); // The playlist itemβs index in the playlist
// Return from the callback synchronously to allow the item to load and play without changes
if (item.verified) {
return;
}
// Return a promise to block playlist progression until resolved
return new Promise(function(resolve, reject) {
return doSomethingAsync(item).then(function(result) {
if (result.ok) {
if (result.modifiedItem) {
// Resolve the promise to resume loading and playback with a new item
resolve(result.modifiedItem);
} else {
// Resolve the promise to resume loading and playback without changes
resolve();
}
} else {
// Reject the promise to skip playback of the playlist item
reject();
}
});
});
});
jwplayer().setPlaylistItemCallback(null);
Argument | Description |
---|---|
callback | A null argument or a function that is passed with the arguments index and itemWhen the callback is a function, it can be invoked asynchronously and pass item (a playlist item) and index (the index of the item in the playlist). When the callback returns a Promise, playlist progression is blocked until the Promise is resolved. If the Promise resolves with a valid playlist object, that object will replace the item in the playlist. Since Promises only resolve once, the function is not repeated when the same item is played more than once.There can only be one active callback. By calling this method again, any existing callback and playlist item Promises are removed. When the callback is null , the callback and all playlist item promises are removed. See also: removePlaylistItemCallback() |