belongs to Maven artifact androidx.media:media:1.0.0-alpha1

MediaPlaylistAgent

public abstract class MediaPlaylistAgent
extends Object

java.lang.Object
   ↳ androidx.media.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 DataSourceDesc) 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(DataSourceDesc dsd)

Called by MediaSession2 when it wants to translate DataSourceDesc from the MediaPlayerInterface.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

int REPEAT_MODE_ALL

Playing media list will be repeated.

Constant Value: 2 (0x00000002)

REPEAT_MODE_GROUP

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

int REPEAT_MODE_NONE

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

Constant Value: 0 (0x00000000)

REPEAT_MODE_ONE

int REPEAT_MODE_ONE

Playback of the current playing media item will be repeated.

Constant Value: 1 (0x00000001)

SHUFFLE_MODE_ALL

int SHUFFLE_MODE_ALL

Media list will be played in shuffled order.

Constant Value: 1 (0x00000001)

SHUFFLE_MODE_GROUP

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

int SHUFFLE_MODE_NONE

Media list will be played in order.

Constant Value: 0 (0x00000000)

Public constructors

MediaPlaylistAgent

MediaPlaylistAgent ()

Public methods

addPlaylistItem

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

MediaItem2 getCurrentMediaItem ()

Returns currently playing media item.

Returns
MediaItem2

getMediaItem

MediaItem2 getMediaItem (DataSourceDesc dsd)

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

Session would throw an exception if this returns null for the dsd from the MediaPlayerInterface.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

List<MediaItem2> getPlaylist ()

Returns the playlist

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

getPlaylistMetadata

MediaMetadata2 getPlaylistMetadata ()

Returns the playlist metadata

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

getRepeatMode

int getRepeatMode ()

Gets the repeat mode

Returns
int repeat mode

getShuffleMode

int getShuffleMode ()

Gets the shuffle mode

Returns
int The shuffle mode

notifyPlaylistChanged

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

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

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

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

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

void removePlaylistItem (MediaItem2 item)

Removes the media item from the playlist

Parameters
item MediaItem2: media item to remove

replacePlaylistItem

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

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

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

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

void skipToNextItem ()

Skips to the next item in the playlist.

skipToPlaylistItem

void skipToPlaylistItem (MediaItem2 item)

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

Parameters
item MediaItem2: media item to start playing from

skipToPreviousItem

void skipToPreviousItem ()

Skips to the previous item in the playlist.

unregisterPlaylistEventCallback

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

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