This is a complete rewrite using a class-based "advanced plugin" structure. This will require a new major version.
Notable changes from old plugin (not an exhaustive list)
Plugin logic is encapsulated within 3 classes:
Playlist - a standalone class that handles all playlist logic that does not require a player instance
PlaylistPlugin - a Video.js plugin class that handles all playlist logic that does require a player instance, ex. loading.
AutoAdvance - handles all auto-advance logic
Playlist instances must be constructed from objects that have a sources array of items with at least src and type properties. Sources may no longer be primitives.
New strategy for getCurrentItem() / getCurrentIndex()
Whenever querying the current item or current index, the old plugin would first have to loop through all the sources in the playlist for one that matched player.currentSrc(). In addition to being confusing since the getter was acting internally as a setter, this added complexity as we had to work around cases where multiple different items could have the same source. This resulted in the playlistItemId unique id concept.
Now, the current index is automatically updated whenever an operation is performed that changes the order or contents of the playlist. The playlistItemId concept has been removed.
Loading and playing behavior changes
playlist.set() (which replaces the player.playlist() setter) now only accepts a single argument and sets the internal playlist abstraction. It does not load an item.
Loading must be initiated afterward by first loading the playlist via playlistPlugin.loadPlaylist(playlist), then calling one of the loading methods (playlistPlugin.loadPlaylistItem(index), playlistPluginloadFirstItem(), etc)
The plugin now only calls player.play() when auto-advancing. If auto-advance is disabled, switching to a different playlist item will not play it.
Removed duringplaylistchange event (see original reasoning for having such an event)
Instead of using this event to intercept the playlist setting process, integrators should do the following:
// Perform sorting operations on the Playlist
playlist.shuffle();
// Load first item after the playlist has been sorted
playlistPlugin.loadFirstItem();
// Alternatively, they can use playlistchange, which happens after setting the playlist and before any item is loaded
player.on('playlistchange', () => {
playlist.shuffle();
playlistPlugin.loadFirstItem();
});
- `playlistchange` is now fired synchronously immediately after the playlist is updated. It is up to integrators to avoid running heavy tasks in playlistchange handlers.
- Methods no longer throw errors.
- Executed @todo changes and removed deprecated functionality
- removed playlistchange event [action](https://github.com/videojs/videojs-playlist/blob/beba231253c9f283cd077c70770fc49384554cb9/docs/api.md#action) property. add() and remove() methods now only trigger playlist and playlist remove, not playlistchange
- playlistchange event fires [every time](https://github.com/videojs/videojs-playlist/blob/beba231253c9f283cd077c70770fc49384554cb9/docs/api.md#backward-compatibility) a playlist is set, even the first time
- If a `remove()` call removes the current item, we set the currentIndex to `null`
- Replaced the [old poster flash solution](https://github.com/videojs/videojs-playlist/blob/beba231253c9f283cd077c70770fc49384554cb9/src/playlist-maker.js#L316-L324) with a non-index-based poster flash solution that will also handle cases when we repeat after the last item
- Various bug fixes
- Added more validation
Description
This is a complete rewrite using a class-based "advanced plugin" structure. This will require a new major version.
Notable changes from old plugin (not an exhaustive list)
Playlist
- a standalone class that handles all playlist logic that does not require a player instancePlaylistPlugin
- a Video.js plugin class that handles all playlist logic that does require a player instance, ex. loading.AutoAdvance
- handles all auto-advance logicPlaylist
instances must be constructed from objects that have a sources array of items with at leastsrc
andtype
properties. Sources may no longer be primitives.playlist.set()
(which replaces theplayer.playlist()
setter) now only accepts a single argument and sets the internal playlist abstraction. It does not load an item.playlistPlugin.loadPlaylist(playlist)
, then calling one of the loading methods (playlistPlugin.loadPlaylistItem(index)
,playlistPluginloadFirstItem()
, etc)// Perform sorting operations on the Playlist playlist.shuffle();
// Load first item after the playlist has been sorted playlistPlugin.loadFirstItem();
// Alternatively, they can use
playlistchange
, which happens after setting the playlist and before any item is loaded player.on('playlistchange', () => { playlist.shuffle(); playlistPlugin.loadFirstItem(); });