0% found this document useful (0 votes)
259 views1 page

ExoPlayer Playlist API Guide

The ExoPlayer playlist API enables sequential playback of multiple media items. It allows adding media items to a playlist, preparing and starting playback. Transitions between items are seamless even if they are different formats or types. The playlist can be dynamically modified by adding, removing or moving items before or during playback. The player will automatically handle modifications to continue playback.

Uploaded by

Jose Arizaca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
259 views1 page

ExoPlayer Playlist API Guide

The ExoPlayer playlist API enables sequential playback of multiple media items. It allows adding media items to a playlist, preparing and starting playback. Transitions between items are seamless even if they are different formats or types. The playlist can be dynamically modified by adding, removing or moving items before or during playback. The player will automatically handle modifications to continue playback.

Uploaded by

Jose Arizaca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

ExoPlayer Javadoc GitHub Blog 

Home

Pros and cons

Demo application Playlists


Supported formats

Supported devices The playlist API is defined by the Player interface, which is implemented by all ExoPlayer implementations. It enables
Glossary sequential playback of multiple media items. The following example shows how to start playback of a playlist containing
two videos:
Getting started

Hello world // Build the media items.


MediaItem firstItem = MediaItem.fromUri(firstVideoUri);
Player events MediaItem secondItem = MediaItem.fromUri(secondVideoUri);
// Add the media items to be played.
Playlists player.addMediaItem(firstItem);
player.addMediaItem(secondItem);
Media items // Prepare the player.
player.prepare();
Media sources // Start the playback.
player.play();
Track selection

UI components
Transitions between items in a playlist are seamless. There’s no requirement that they’re of the same format (e.g., it’s
Downloading media fine for a playlist to contain both H264 and VP9 videos). They may even be of different types (e.g., it’s fine for a playlist
Ad insertion to contain both videos and audio only streams). It’s allowed to use the same MediaItem multiple times within a playlist.
Live streaming

Debug logging
Modifying the playlist
Analytics

Media types It’s possible to dynamically modify a playlist by adding, moving and removing media items. This can be done both before
and during playback by calling the corresponding playlist API methods:
DASH

HLS // Adds a media item at position 1 in the playlist.


player.addMediaItem(/* index= */ 1, MediaItem.fromUri(thirdUri));
SmoothStreaming // Moves the third media item from position 2 to the start of the playlist.
player.moveMediaItem(/* currentIndex= */ 2, /* newIndex= */ 0);
Progressive // Removes the first item from the playlist.
player.removeMediaItem(/* index= */ 0);
Advanced topics

Digital rights management Replacing and clearing the entire playlist are also supported:

Troubleshooting
// Replaces the playlist with a new one.
Customization List<MediaItem> newItems = ImmutableList.of(
MediaItem.fromUri(fourthUri),
Transforming media MediaItem.fromUri(fifthUri));
player.setMediaItems(newItems, /* resetPosition= */ true);
Battery consumption // Clears the playlist. If prepared, the player transitions to the ended state.
player.clearMediaItems();
APK shrinking

OEM testing
The player automatically handles modifications during playback in the correct way. For example if the currently playing
Design documents media item is moved, playback is not interrupted and its new successor will be played upon completion. If the currently
playing MediaItem is removed, the player will automatically move to playing the first remaining successor, or transition to
the ended state if no such successor exists.

Querying the playlist


The playlist can be queried using Player.getMediaItemCount and Player.getMediaItemAt . The currently playing media item
can be queried by calling Player.getCurrentMediaItem .

Identifying playlist items


To identify playlist items, MediaItem.mediaId can be set when building the item:

// Build a media item with a media ID.


MediaItem mediaItem =
new MediaItem.Builder().setUri(uri).setMediaId(mediaId).build();

If an app does not explicitly define a media ID for a media item, the string representation of the URI is used.

Associating app data with playlist items


In addition to an ID, each media item can also be configured with a custom tag, which can be any app provided object.
One use of custom tags is to attach metadata to each media item:

You might also like