Create a playlist (Android v3)
Create and add playlists to your Android app.
There are multiple ways to load and play content in your player. As best practice approaches, we recommend the following:
- Use
PlaylistItem.Builder()
to create single-item or multiple-item playlists - Use
PlayerConfig.Builder()
to associate a playlist to a player and to initiate media playback
While you can use other approaches to create, associate, and play playlists, PlaylistItem.Builder()
and PlayerConfig.Builder()
enable you to add functionality like customization and advertising.
The following sections explain how to create a single-item playlist, create a multiple-item playlist, and add multiple sources to a playlist item.
Create a single-item playlist
As mentioned in Add a player to an activity, the following steps explain how to add a single-item playlist to a player:
- Use
PlaylistItem.Builder()
to create and name aPlaylistItem
object, for example,playlistItem
. - Add the video file URL (
file
).
For videos hosted with JWP, click the name of the video on the video list page. Next, click the ASSETS tab. Then under Sources, click the name of the source to reveal the Direct Link. Hosting your videos with JWP enables you to query the Analytics API to access SDK video metrics. - (Optional) Add a poster image (
image
) and video metadata (title
,description
) - Create a
List<PlaylistItem>
object and name it, for example,playlist
. - Add
playlistItem
toplaylist
. - Use
PlayerConfig.Builder()
to create aconfig
object that defines the properties of the player. - Assign
playlist
toconfig
. - Set up
JWPlayerView
--mPlayerView
in the following example -- withconfig
.
PlaylistItem playlistItem = new PlaylistItem.Builder()
.file("https://cdn.jwplayer.com/manifests/{media_id}.m3u8")
.image("https://www.mydomain.com/poster.jpg")
.title("Playlist-Item Title")
.description("Some really great content")
.build();
List<PlaylistItem> playlist = new ArrayList<>();
playlist.add(playlistItem);
PlayerConfig config = new PlayerConfig.Builder()
.playlist(playlist)
.build();
mPlayerView.setup(config);
Create a multiple-item playlist
To create a multiple-item playlist, create multiple named PlaylistItem
objects and add them to a playlist
object:
- Use
PlaylistItem.Builder()
to create and name aPlaylistItem
object, for example,playlistItem
. - Add the video file URL (
file
).
For videos hosted with JWP, click the name of the video on the video list page. Next, click the ASSETS tab. Then under Sources, click the name of the source to reveal the Direct Link. Hosting your videos with JWP enables you to query the Analytics API to access SDK video metrics. - (Optional) Add a poster image (
image
) and video metadata (title
,description
). - Repeat steps 1-3 each video to include in a playlist. When creating additional
PlaylistItem
objects, give each a unique name, for example,playlistItem2
,playlistItem3
. - Create a List object and name it, for example,
playlist
. - Add all
PlaylistItem
objects toplaylist
. - Use
PlayerConfig.Builder()
to create aconfig
object that defines the properties of the player. - Assign
playlist
toconfig
. - Set up
JWPlayerView
--mPlayerView
in the following example -- withconfig
.
PlaylistItem playlistItem = new PlaylistItem.Builder()
.file("https://cdn.jwplayer.com/manifests/{media_id}.m3u8")
.image("https://www.mydomain.com/poster.jpg")
.title("Playlist-Item Title")
.description("Some really great content")
.build();
PlaylistItem playlistItem2 = new PlaylistItem.Builder()
.file("https://cdn.jwplayer.com/manifests/{media_id2}.m3u8")
.image("https://www.mydomain.com/poster2.jpg")
.title("Playlist-Item2 Title")
.description("Some really great content")
.build();
List<PlaylistItem> playlist = new ArrayList<>();
playlist.add(playlistItem);
playlist.add(playlistItem2);
PlayerConfig config = new PlayerConfig.Builder()
.playlist(playlist)
.build();
mPlayerView.setup(config);
Add multiple sources to a playlist item
You can also associate multiple sources to a playlist item. This is useful when you want to offer your viewers an option between a high definition or standard definition variation of your content.
The following steps explain how to add multiple sources to a playlist item:
- Create a
List<MediaSource>
object and name it, for example,mediaSources
. - Add the URLs for your sources to
mediaSources
.
For videos hosted with JWP, click the name of the video on the video list page. Next, click the ASSETS tab. Then under Sources, click the name of the source to reveal the Direct Link. Hosting your videos with JWP enables you to query the Analytics API to access SDK video metrics. - Use
PlaylistItem.Builder()
to create and name aPlaylistItem
object, for example,playlistItem
. - Use the
source
property to addmediaSources
toplaylistItem
. - (Optional) Add a poster image (
image
) and video metadata (title
,description
). - Create a
List<PlaylistItem>
object and name it, for example,playlist
. - Add
playlistItem
toplaylist
. - Use
PlayerConfig.Builder()
to create aconfig
object that defines the properties of the player. - Assign
playlist
toconfig
. - Set up the
JWPlayerView
--mPlayerView
in the following example -- withconfig
.
List<MediaSource> mediaSources = new ArrayList<>();
mediaSources.add(new MediaSource("https://cdn.jwplayer.com/manifests/{media_id_hd}.m3u8"));
mediaSources.add(new MediaSource("https://cdn.jwplayer.com/manifests/{media_id_sd}.m3u8"));
PlaylistItem playlistItem = new PlaylistItem.Builder()
.sources(mediaSources)
.image("https://www.mydomain.com/poster.jpg")
.description("Some really great content")
.title("Playlist-Item Title")
.build();
List<PlaylistItem> playlist = new ArrayList<>();
playlist.add(playlistItem);
PlayerConfig config = new PlayerConfig.Builder()
.playlist(playlist)
.build();
mPlayerView.setup(config);
Frequently used methods and callbacks
The following tables list frequently used methods and callbacks. To view all available methods and callbacks, visit our SDK reference.
Methods
Method | Description |
---|---|
List getPlaylist() | Returns the player's current playlist |
int getPlaylistIndex() | Returns the index of the currently active item in the playlist |
PlaylistItem getPlaylistItem(int index) | Returns the currently playing PlaylistItem |
JWPlayerView callbacks
Callback | Description |
---|---|
onPlaylist(PlaylistEvent playlistEvent) | Fired when a new playlist has been loaded into the player. |
onPlaylistItem(PlaylistItemEvent playlistItemEvent) | Fired when the playlist index changes to a new playlist item. |
onPlaylistComplete(PlaylistCompleteEvent playlistCompleteEvent) | Fired when the player is done playing all items in the playlist. However, if the repeat option is set true, this is never fired. |
Updated about 1 year ago