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:

  1. Use PlaylistItem.Builder() to create and name a PlaylistItem object, for example, playlistItem.
  2. 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.

  3. (Optional) Add a poster image (image) and video metadata (title, description)
  4. Create a List<PlaylistItem> object and name it, for example, playlist.
  5. Add playlistItem to playlist.
  6. Use PlayerConfig.Builder() to create a config object that defines the properties of the player.
  7. Assign playlist to config.
  8. Set up JWPlayerView -- mPlayerView in the following example -- with config.
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:

  1. Use PlaylistItem.Builder() to create and name a PlaylistItem object, for example, playlistItem.
  2. 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.

  3. (Optional) Add a poster image (image) and video metadata (title, description).
  4. 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.
  5. Create a List object and name it, for example, playlist.
  6. Add all PlaylistItem objects to playlist.
  7. Use PlayerConfig.Builder() to create a config object that defines the properties of the player.
  8. Assign playlist to config.
  9. Set up JWPlayerView -- mPlayerView in the following example -- with config.
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:

  1. Create a List<MediaSource> object and name it, for example, mediaSources.
  2. 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.

  3. Use PlaylistItem.Builder() to create and name a PlaylistItem object, for example, playlistItem.
  4. Use the source property to add mediaSources to playlistItem.
  5. (Optional) Add a poster image (image) and video metadata (title, description).
  6. Create a List<PlaylistItem> object and name it, for example, playlist.
  7. Add playlistItem to playlist.
  8. Use PlayerConfig.Builder() to create a config object that defines the properties of the player.
  9. Assign playlist to config.
  10. Set up the JWPlayerView -- mPlayerView in the following example -- with config.
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

MethodDescription
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

CallbackDescription
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.