Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

belongs to Maven artifact androidx.media2:media2:1.0.0-alpha02

MediaPlaylistAgent

public abstract class MediaPlaylistAgent
extends Object

java.lang.Object
   ↳ androidx.media2.MediaPlaylistAgent


MediaPlaylistAgent is the abstract class an application needs to derive from to pass an object to a MediaSession2 that will override default playlist handling behaviors. It contains a set of notify methods to signal MediaSession2 that playlist-related state has changed.

Playlists are composed of one or multiple MediaItem2 instances, which combine metadata and data sources (as DataSourceDesc2) Used by MediaSession2 and MediaController2.

Summary

Nested classes

class MediaPlaylistAgent.PlaylistEventCallback

A callback class to receive notifications for events on the media player. 

Constants

int REPEAT_MODE_ALL

Playing media list will be repeated.

int REPEAT_MODE_GROUP

Playback of the playing media group will be repeated.

int REPEAT_MODE_NONE

Playback will be stopped at the end of the playing media list.

int REPEAT_MODE_ONE

Playback of the current playing media item will be repeated.

int SHUFFLE_MODE_ALL

Media list will be played in shuffled order.

int SHUFFLE_MODE_GROUP

Media group will be played in shuffled order.

int SHUFFLE_MODE_NONE

Media list will be played in order.

Public constructors

MediaPlaylistAgent()

Public methods

abstract void addPlaylistItem(int index, MediaItem2 item)

Adds the media item to the playlist at position index.

abstract MediaItem2 getCurrentMediaItem()

Returns currently playing media item.

MediaItem2 getMediaItem(DataSourceDesc2 dsd)

Called by MediaSession2 when it wants to translate DataSourceDesc2 from the BaseMediaPlayer.PlayerEventCallback to the MediaItem2.

abstract List<MediaItem2> getPlaylist()

Returns the playlist

abstract MediaMetadata2 getPlaylistMetadata()

Returns the playlist metadata

abstract int getRepeatMode()

Gets the repeat mode

abstract int getShuffleMode()

Gets the shuffle mode

final void notifyPlaylistChanged()

Notifies the current playlist and playlist metadata.

final void notifyPlaylistMetadataChanged()

Notifies the current playlist metadata.

final void notifyRepeatModeChanged()

Notifies the current repeat mode.

final void notifyShuffleModeChanged()

Notifies the current shuffle mode.

final void registerPlaylistEventCallback(Executor executor, MediaPlaylistAgent.PlaylistEventCallback callback)

Register MediaPlaylistAgent.PlaylistEventCallback to listen changes in the underlying MediaPlaylistAgent.

abstract void removePlaylistItem(MediaItem2 item)

Removes the media item from the playlist

abstract void replacePlaylistItem(int index, MediaItem2 item)

Replace the media item at index in the playlist.

abstract void setPlaylist(List<MediaItem2> list, MediaMetadata2 metadata)

Sets the playlist with the metadata.

abstract void setRepeatMode(int repeatMode)

Sets the repeat mode.

abstract void setShuffleMode(int shuffleMode)

Sets the shuffle mode.

abstract void skipToNextItem()

Skips to the next item in the playlist.

abstract void skipToPlaylistItem(MediaItem2 item)

Skips to the the media item, and plays from it.

abstract void skipToPreviousItem()

Skips to the previous item in the playlist.

final void unregisterPlaylistEventCallback(MediaPlaylistAgent.PlaylistEventCallback callback)

Unregister the previously registered MediaPlaylistAgent.PlaylistEventCallback.

abstract void updatePlaylistMetadata(MediaMetadata2 metadata)

Updates the playlist metadata.

Inherited methods

Constants

REPEAT_MODE_ALL

public static final int REPEAT_MODE_ALL

Playing media list will be repeated.

Constant Value: 2 (0x00000002)

REPEAT_MODE_GROUP

public static final int REPEAT_MODE_GROUP

Playback of the playing media group will be repeated. A group is a logical block of media items which is specified in the section 5.7 of the Bluetooth AVRCP 1.6. An example of a group is the playlist.

Constant Value: 3 (0x00000003)

REPEAT_MODE_NONE

public static final int REPEAT_MODE_NONE

Playback will be stopped at the end of the playing media list.

Constant Value: 0 (0x00000000)

REPEAT_MODE_ONE

public static final int REPEAT_MODE_ONE

Playback of the current playing media item will be repeated.

Constant Value: 1 (0x00000001)

SHUFFLE_MODE_ALL

public static final int SHUFFLE_MODE_ALL

Media list will be played in shuffled order.

Constant Value: 1 (0x00000001)

SHUFFLE_MODE_GROUP

public static final int SHUFFLE_MODE_GROUP

Media group will be played in shuffled order. A group is a logical block of media items which is specified in the section 5.7 of the Bluetooth AVRCP 1.6. An example of a group is the playlist.

Constant Value: 2 (0x00000002)

SHUFFLE_MODE_NONE

public static final int SHUFFLE_MODE_NONE

Media list will be played in order.

Constant Value: 0 (0x00000000)

Public constructors

MediaPlaylistAgent

public MediaPlaylistAgent ()

Public methods

addPlaylistItem

public abstract void addPlaylistItem (int index, 
                MediaItem2 item)

Adds the media item to the playlist at position index. Index equals or greater than the current playlist size (e.g. Integer.MAX_VALUE) will add the item at the end of the playlist.

This will not change the currently playing media item. If index is less than or equal to the current index of the playlist, the current index of the playlist will be incremented correspondingly.

Parameters
index int: the index you want to add

item MediaItem2: the media item you want to add

getCurrentMediaItem

public abstract MediaItem2 getCurrentMediaItem ()

Returns currently playing media item.

Returns
MediaItem2

getMediaItem

public MediaItem2 getMediaItem (DataSourceDesc2 dsd)

Called by MediaSession2 when it wants to translate DataSourceDesc2 from the BaseMediaPlayer.PlayerEventCallback to the MediaItem2. Override this method if you want to create DataSourceDesc2s dynamically, instead of specifying them with setPlaylist(List, MediaMetadata2).

Session would throw an exception if this returns null for the dsd from the BaseMediaPlayer.PlayerEventCallback.

Default implementation calls the getPlaylist() and searches the MediaItem2 with the .

Returns
MediaItem2 A MediaItem2 object in the playlist that matches given dsd.

Throws
IllegalArgumentException if dsd is null

getPlaylist

public abstract List<MediaItem2> getPlaylist ()

Returns the playlist

Returns
List<MediaItem2> playlist, or null if none is set.

getPlaylistMetadata

public abstract MediaMetadata2 getPlaylistMetadata ()

Returns the playlist metadata

Returns
MediaMetadata2 metadata metadata of the playlist, or null if none is set

getRepeatMode

public abstract int getRepeatMode ()

Gets the repeat mode

Returns
int repeat mode

getShuffleMode

public abstract int getShuffleMode ()

Gets the shuffle mode

Returns
int The shuffle mode

notifyPlaylistChanged

public final void notifyPlaylistChanged ()

Notifies the current playlist and playlist metadata. Call this API when the playlist is changed.

Registered MediaPlaylistAgent.PlaylistEventCallback would receive this event through the MediaPlaylistAgent.PlaylistEventCallback.onPlaylistChanged(MediaPlaylistAgent, List, MediaMetadata2).

notifyPlaylistMetadataChanged

public final void notifyPlaylistMetadataChanged ()

Notifies the current playlist metadata. Call this API when the playlist metadata is changed.

Registered MediaPlaylistAgent.PlaylistEventCallback would receive this event through the MediaPlaylistAgent.PlaylistEventCallback.onPlaylistMetadataChanged(MediaPlaylistAgent, MediaMetadata2).

notifyRepeatModeChanged

public final void notifyRepeatModeChanged ()

Notifies the current repeat mode. Call this API when the repeat mode is changed.

Registered MediaPlaylistAgent.PlaylistEventCallback would receive this event through the MediaPlaylistAgent.PlaylistEventCallback.onRepeatModeChanged(MediaPlaylistAgent, int).

notifyShuffleModeChanged

public final void notifyShuffleModeChanged ()

Notifies the current shuffle mode. Call this API when the shuffle mode is changed.

Registered MediaPlaylistAgent.PlaylistEventCallback would receive this event through the MediaPlaylistAgent.PlaylistEventCallback.onShuffleModeChanged(MediaPlaylistAgent, int).

registerPlaylistEventCallback

public final void registerPlaylistEventCallback (Executor executor, 
                MediaPlaylistAgent.PlaylistEventCallback callback)

Register MediaPlaylistAgent.PlaylistEventCallback to listen changes in the underlying MediaPlaylistAgent.

Parameters
executor Executor: a callback Executor

callback MediaPlaylistAgent.PlaylistEventCallback: a PlaylistEventCallback

Throws
IllegalArgumentException if executor or callback is null.

removePlaylistItem

public abstract void removePlaylistItem (MediaItem2 item)

Removes the media item from the playlist

Parameters
item MediaItem2: media item to remove

replacePlaylistItem

public abstract void replacePlaylistItem (int index, 
                MediaItem2 item)

Replace the media item at index in the playlist. This can be also used to update metadata of an item.

Parameters
index int: the index of the item to replace

item MediaItem2: the new item

setPlaylist

public abstract void setPlaylist (List<MediaItem2> list, 
                MediaMetadata2 metadata)

Sets the playlist with the metadata.

When the playlist is changed, call notifyPlaylistChanged() to notify changes to the registered callbacks.

Parameters
list List: playlist

metadata MediaMetadata2: metadata of the playlist

setRepeatMode

public abstract void setRepeatMode (int repeatMode)

Sets the repeat mode.

When the repeat mode is changed, call notifyRepeatModeChanged() to notify changes to the registered callbacks.

Parameters
repeatMode int: repeat mode

setShuffleMode

public abstract void setShuffleMode (int shuffleMode)

Sets the shuffle mode.

When the shuffle mode is changed, call notifyShuffleModeChanged() to notify changes to the registered callbacks.

Parameters
shuffleMode int: The shuffle mode

skipToNextItem

public abstract void skipToNextItem ()

Skips to the next item in the playlist.

skipToPlaylistItem

public abstract void skipToPlaylistItem (MediaItem2 item)

Skips to the the media item, and plays from it.

Parameters
item MediaItem2: media item to start playing from

skipToPreviousItem

public abstract void skipToPreviousItem ()

Skips to the previous item in the playlist.

unregisterPlaylistEventCallback

public final void unregisterPlaylistEventCallback (MediaPlaylistAgent.PlaylistEventCallback callback)

Unregister the previously registered MediaPlaylistAgent.PlaylistEventCallback.

Parameters
callback MediaPlaylistAgent.PlaylistEventCallback: the callback to be removed

Throws
IllegalArgumentException if the callback is null.

updatePlaylistMetadata

public abstract void updatePlaylistMetadata (MediaMetadata2 metadata)

Updates the playlist metadata.

When the playlist metadata is changed, call notifyPlaylistMetadataChanged() to notify changes to the registered callbacks.

Parameters
metadata MediaMetadata2: metadata of the playlist