Create a playlist

Create and add playlists to your Android app.


The PlaylistItem class enables you to add content to your player and define the unique characteristics of that content:

  • Title
  • Description
  • Poster image
  • Media ID

There are multiple ways to load and play content in your player. As best practice approaches, we recommend the following:

  • Use PlayerConfig.Builder() to create single-item or multiple-item playlists with media hosted in your JW Player account
  • Use PlaylistItem.Builder() to create single-item or multiple-item playlists with self-hosted media
  • 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.



JW Player-hosted Content

When your content is hosted with JW Player, the metadata added to a media item when it is uploaded to your account is used in your mobile app. Additionally, you have the ability to query the Analytics API to access SDK video metrics.


Create a playlist

  1. Use PlayerConfig.Builder() to create a config object that defines the properties of the player.
  2. Define playlistUrl with a playlist hosted in your JW Player account.
  3. Assign playlistUrl to config.
  4. Set up JWPlayer -- mPlayer in the following example -- with config.

PlayerConfig config = new PlayerConfig.Builder()
        .playlistUrl("https://cdn.jwplayer.com/v2/playlists/a12bc3D4")
        .build();
mPlayer.setup(config);


Self-hosted Content

If you are self-hosting your content, you can set metadata for manually built single-item and multiple-item playlists.


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).
  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 JWPlayer -- mPlayer 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();
mPlayer.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).
  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<PlaylistItem> 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 JWPlayer -- mPlayer 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();
mPlayer.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.
  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 JWPlayer -- mPlayer 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();
mPlayer.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<PlaylistItem> 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.


Did this page help you?