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: