Playlist Player SDK (legacy)
This guide explains how to embed a custom playlist and custom-build a playlist player using our JavaScript Playlist Player SDK. You can choose any combination of audios from a project.
The JavaScript Playlist Player SDK is client-side JavaScript library that is separate from the API. You connect to it differently, and it gives you a different range of options.
Install
You can install the JavaScript Playlist Player and SDK through NPM:
Or, you can also reference an up‐to‐date version on our CDN:
Initialize
To initialize the JavaScript Playlist Player, use the following:
To intialize the JavaScript Playlist Player with the SDK, import the package:
Then use the following:
The Playlist Player SDK will now be available, and you will be able to use the JavaScript Playlist Player SDK.
Required parameters
Parameter | Type | Description |
---|---|---|
| string | To use the Playlist Player set this to: |
| integer (conditional) | Set the |
| integer (conditional) | Set the |
| array (conditional) | Array of objects like |
Example for array of playlist with podcast ID's:
Example for array of playlist with podcast ID and Playlist ID:
Optional parameters
Parameter | Type | Description |
---|---|---|
| string | This is the ID of the container element. The default is set to |
| boolean | Set to false to use your own UI |
| string | Set the color of the Player icons and progress bar, e.g, |
| string | Set the color of the Player text, e.g, |
| string | Set the color of the Player background, e.g, |
| integer | The number of items to show in the playlist before a scrollbar appears |
Player methods
Once the Player is set up, various methods are available to control the audio, set the Player language, or obtain information about the Player state.
Player methods can be called directly, e.g. AppInst.play()
, or you can create an new object within the window object and add the methods you want available, as shown here:
Methods can be called like so: YourApp.paused()
.
Methods
Method | Type | Description |
---|---|---|
| - | Play the audio |
The play()
also returns a promise which can be resolved when playback has started, or is rejected if for some reason playback cannot be started.
Method | Type | Description |
---|---|---|
| - | Pause the audio |
| string | Set the text language in the player, e.g. |
| - | Get the current time in seconds, rounded to two decimal places, e.g. |
| - | Get the total duration of the audio in seconds, rounded to two decimal places, e.g. |
| - | Get the time remaining of the audio in seconds, rounded to two decimal places, e.g. |
| number | Set play position between 0 and total duration in seconds, rounded to two decimal places, e.g. |
| number | Rewind the playback by the specified seek time in seconds, e.g. |
| number | Forward the playback by the specified seek time in seconds, e.g. |
| - | Get the current audio index in the playlist |
| number | Set audio index in the playlist |
| - | Skip to the previous audio in the playlist |
| - | Skip to the next audio in the playlist |
| - | Returns an array with a list of audio objects |
| number | Returns the audio object in that index |
| Returns a promise from which you can get data from the parameter list |
Example for parameter arrayIDs
:
Returns a promise list of audios:
Method | Type | Description |
---|---|---|
| promise | Checks whether the audio has been processed or not |
Method | Type | Description |
---|---|---|
| - | Get the playback rate |
| number | Set the playback rate. It accepts any numeric value from the following list: |
| - | Get the media object being played. |
| object | Set the Player colors for light and dark modes. |
Playlist Player events
You can run custom functions based on specific Playlist Player events using the on
and off
listener to bind your functions to the events:
appInst.events
supported a next methods
on(type, handler)
: Register an event handler for the given typeoff(type, handler)
: Remove an event handler for the given type
play
This event fires when playback is initiated.
Event data
duration
number
The total duration of the audio in seconds, rounded to two decimal places, e.g. 28.05
.
---
progress
number
The duration of the audio already played in seconds, rounded to two decimal places, e.g. 28.05
.
---
index
number
The index of the audio already played.
Sample event data
pause
This event fires when audio is paused.
Event data
duration
number
The total duration of the audio in seconds, rounded to two decimal places, e.g. 28.05
.
---
progress
number
The duration of the audio played, when the pause was triggered, in seconds, rounded to two decimal places, e.g. 28.05
.
---
index
number
The index of the audio already played.
Sample event data
timeUpdate
This event fires every 25ms during playback and indicates, in seconds, the duration of the audio that has been played, e.g. 28.05
.
Event data
duration
number
The total duration of the audio in seconds, rounded to two decimal places, e.g. 28.05
.
---
progress
number
The duration of the audio played in seconds, rounded to two decimal places, e.g. 28.05
.
---
index
number
The index of the audio already played.
Sample event data
playbackRate
This event fires when the playback rate of the audio in the Playlist Player changes.
Event data
playbackRate
number
The new playback rate, e.g. 1.5
.
ended
This event fires when the audio completes playback.
Event data
index
number
The index of the audio was ended.
Last updated