Playlists
Playlist
s are reactive lists of videos that can be played and observed efficiently, with built-in
support for pagination, caching and preloading. This is the recommended way of fetching and
playing videos through our player.
As with querying videos, the start point is the video store (VideoKit.videos()
).
Also, to fetch playlist you will need a valid session or the call will return an error.
#
Inspecting playlistsEvery playlist holds a list of videos in memory. At first, this list represent the first "page" of
results that were retrieved from server. These videos can be retrieved with Playlist.getVideo
:
If getVideo
is called with an index bigger than playlist.size
, it will throw an exception.
If you need more videos than those available at the moment, you can request a new batch of results
by using Playlist.loadMore()
:
Note that if Playlist.loadMoreOnAccess
is true (default), the playlist will automatically load new
pages as you consume the playlist with getVideo
, checking if you are getting close enough to the last
available video. This makes it easy to show a list of videos without worrying about dynamic contents.
#
Observing playlistsPlaylists can be observed by registering a PlaylistListener
. This is extremely useful when
videos are shown in a RecyclerView
, for example, so that you can call the appropriate notify*
methods whenever something changes.
#
Obtain playlistsAs with other APIs, we use request objects to define the query parameters. All request objects
extend the PlaylistRequest
interface. We expose several types of requests, each one with different
configuration options.
Once you have the request, just call getPlaylist
:
#
By userYou can filter by user using UserPlaylistRequest
:
#
By metadata and tagsYou can filter by metadata and tags using FilteredPlaylistRequest
:
#
Custom playlistsYou can create a playlist with custom videos using CustomPlaylistRequest
:
This is a special type of playlist which can be controlled by the user.
- It is mutable! You can use
add
orremove
functions to add ids, and videos will be loaded accordingly - It can't support the concept of page, so
loadMore
does nothing.
#
PreloadingAs you access videos (through getVideo
) and consume them (through the player SDK), the playlist
will automatically cache video data and preload videos that we think you might request soon. You
can customize the preload quality using preloadQuality
:
You can also choose whether to enable HLS playback or not using the preloadUseHls
boolean:
When passing the playlist to a player, it is fundamental that these settings match
the player values, Player.playbackQuality
and Player.useHls
respectively, otherwise preloading will
be wasting useful resources.