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

MediaSession2.SessionCallback

public static abstract class MediaSession2.SessionCallback
extends Object

java.lang.Object
   ↳ androidx.media.MediaSession2.SessionCallback


Callback to be called for all incoming commands from MediaController2s.

If it's not set, the session will accept all controllers and all incoming commands by default.

Summary

Public constructors

MediaSession2.SessionCallback()

Public methods

void onBufferingStateChanged(MediaSession2 session, MediaPlayerInterface player, MediaItem2 item, int state)

Called to report buffering events for a data source.

boolean onCommandRequest(MediaSession2 session, MediaSession2.ControllerInfo controller, SessionCommand2 command)

Called when a controller sent a command which will be sent directly to one of the following:

Return false here to reject the request and stop sending command.

SessionCommandGroup2 onConnect(MediaSession2 session, MediaSession2.ControllerInfo controller)

Called when a controller is created for this session.

void onCurrentMediaItemChanged(MediaSession2 session, MediaPlayerInterface player, MediaItem2 item)

Called when the player's current playing item is changed

When it's called, you should invalidate previous playback information and wait for later callbacks.

void onCustomCommand(MediaSession2 session, MediaSession2.ControllerInfo controller, SessionCommand2 customCommand, Bundle args, ResultReceiver cb)

Called when a controller sent a custom command through MediaController2.sendCustomCommand(SessionCommand2, Bundle, ResultReceiver).

void onDisconnected(MediaSession2 session, MediaSession2.ControllerInfo controller)

Called when a controller is disconnected

void onFastForward(MediaSession2 session, MediaSession2.ControllerInfo controller)

Called when a controller called MediaController2.fastForward()

void onMediaPrepared(MediaSession2 session, MediaPlayerInterface player, MediaItem2 item)

Called when the player is prepared, i.e.

void onPlayFromMediaId(MediaSession2 session, MediaSession2.ControllerInfo controller, String mediaId, Bundle extras)

Called when a controller requested to play a specific mediaId through MediaController2.playFromMediaId(String, Bundle).

void onPlayFromSearch(MediaSession2 session, MediaSession2.ControllerInfo controller, String query, Bundle extras)

Called when a controller requested to begin playback from a search query through MediaController2.playFromSearch(String, Bundle)

An empty query indicates that the app may play any music.

void onPlayFromUri(MediaSession2 session, MediaSession2.ControllerInfo controller, Uri uri, Bundle extras)

Called when a controller requested to play a specific media item represented by a URI through MediaController2.playFromUri(Uri, Bundle)

void onPlaybackSpeedChanged(MediaSession2 session, MediaPlayerInterface player, float speed)

Called to indicate that the playback speed has changed.

void onPlayerStateChanged(MediaSession2 session, MediaPlayerInterface player, int state)

Called to indicate that the state of the player has changed.

void onPlaylistChanged(MediaSession2 session, MediaPlaylistAgent playlistAgent, List<MediaItem2> list, MediaMetadata2 metadata)

Called when a playlist is changed from the MediaPlaylistAgent.

void onPlaylistMetadataChanged(MediaSession2 session, MediaPlaylistAgent playlistAgent, MediaMetadata2 metadata)

Called when a playlist metadata is changed.

void onPrepareFromMediaId(MediaSession2 session, MediaSession2.ControllerInfo controller, String mediaId, Bundle extras)

Called when a controller requested to prepare for playing a specific mediaId through MediaController2.prepareFromMediaId(String, Bundle).

void onPrepareFromSearch(MediaSession2 session, MediaSession2.ControllerInfo controller, String query, Bundle extras)

Called when a controller requested to prepare playback from a search query through MediaController2.prepareFromSearch(String, Bundle).

void onPrepareFromUri(MediaSession2 session, MediaSession2.ControllerInfo controller, Uri uri, Bundle extras)

Called when a controller requested to prepare a specific media item represented by a URI through MediaController2.prepareFromUri(Uri, Bundle).

void onRepeatModeChanged(MediaSession2 session, MediaPlaylistAgent playlistAgent, int repeatMode)

Called when the repeat mode is changed.

void onRewind(MediaSession2 session, MediaSession2.ControllerInfo controller)

Called when a controller called MediaController2.rewind()

void onSeekCompleted(MediaSession2 session, MediaPlayerInterface player, long position)

Called to indicate that MediaSession2.seekTo(long) is completed.

void onSelectRoute(MediaSession2 session, MediaSession2.ControllerInfo controller, Bundle route)

Called when a controller called MediaController2.selectRoute(Bundle).

void onSetRating(MediaSession2 session, MediaSession2.ControllerInfo controller, String mediaId, Rating2 rating)

Called when a controller set rating of a media item through MediaController2.setRating(String, Rating2).

void onShuffleModeChanged(MediaSession2 session, MediaPlaylistAgent playlistAgent, int shuffleMode)

Called when the shuffle mode is changed.

void onSubscribeRoutesInfo(MediaSession2 session, MediaSession2.ControllerInfo controller)

Called when a controller called MediaController2.subscribeRoutesInfo() Session app should notify the routes information by calling MediaSession2.notifyRoutesInfoChanged(ControllerInfo, List).

void onUnsubscribeRoutesInfo(MediaSession2 session, MediaSession2.ControllerInfo controller)

Called when a controller called MediaController2.unsubscribeRoutesInfo()

Inherited methods

Public constructors

MediaSession2.SessionCallback

MediaSession2.SessionCallback ()

Public methods

onBufferingStateChanged

void onBufferingStateChanged (MediaSession2 session, 
                MediaPlayerInterface player, 
                MediaItem2 item, 
                int state)

Called to report buffering events for a data source.

Parameters
session MediaSession2: the session for this event

player MediaPlayerInterface: the player for this event

item MediaItem2: the media item for which buffering is happening.

state int: the new buffering state.

onCommandRequest

boolean onCommandRequest (MediaSession2 session, 
                MediaSession2.ControllerInfo controller, 
                SessionCommand2 command)

Called when a controller sent a command which will be sent directly to one of the following:

Return false here to reject the request and stop sending command.

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information.

command SessionCommand2: a command. This method will be called for every single command.

Returns
boolean true if you want to accept incoming command. false otherwise.

See also:

onConnect

SessionCommandGroup2 onConnect (MediaSession2 session, 
                MediaSession2.ControllerInfo controller)

Called when a controller is created for this session. Return allowed commands for controller. By default it allows all connection requests and commands.

You can reject the connection by return null. In that case, controller receives MediaController2.ControllerCallback.onDisconnected(MediaController2) and cannot be usable.

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information.

Returns
SessionCommandGroup2 allowed commands. Can be null to reject connection.

onCurrentMediaItemChanged

void onCurrentMediaItemChanged (MediaSession2 session, 
                MediaPlayerInterface player, 
                MediaItem2 item)

Called when the player's current playing item is changed

When it's called, you should invalidate previous playback information and wait for later callbacks.

Parameters
session MediaSession2: the controller for this event

player MediaPlayerInterface: the player for this event

item MediaItem2: new item

onCustomCommand

void onCustomCommand (MediaSession2 session, 
                MediaSession2.ControllerInfo controller, 
                SessionCommand2 customCommand, 
                Bundle args, 
                ResultReceiver cb)

Called when a controller sent a custom command through MediaController2.sendCustomCommand(SessionCommand2, Bundle, ResultReceiver).

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

customCommand SessionCommand2: custom command.

args Bundle: optional arguments

cb ResultReceiver: optional result receiver

onDisconnected

void onDisconnected (MediaSession2 session, 
                MediaSession2.ControllerInfo controller)

Called when a controller is disconnected

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

onFastForward

void onFastForward (MediaSession2 session, 
                MediaSession2.ControllerInfo controller)

Called when a controller called MediaController2.fastForward()

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

onMediaPrepared

void onMediaPrepared (MediaSession2 session, 
                MediaPlayerInterface player, 
                MediaItem2 item)

Called when the player is prepared, i.e. it is ready to play the content referenced by the given data source.

Parameters
session MediaSession2: the session for this event

player MediaPlayerInterface: the player for this event

item MediaItem2: the media item for which buffering is happening

onPlayFromMediaId

void onPlayFromMediaId (MediaSession2 session, 
                MediaSession2.ControllerInfo controller, 
                String mediaId, 
                Bundle extras)

Called when a controller requested to play a specific mediaId through MediaController2.playFromMediaId(String, Bundle).

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

mediaId String: media id

extras Bundle: optional extra bundle

onPlayFromSearch

void onPlayFromSearch (MediaSession2 session, 
                MediaSession2.ControllerInfo controller, 
                String query, 
                Bundle extras)

Called when a controller requested to begin playback from a search query through MediaController2.playFromSearch(String, Bundle)

An empty query indicates that the app may play any music. The implementation should attempt to make a smart choice about what to play.

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

query String: query string. Can be empty to indicate any suggested media

extras Bundle: optional extra bundle

onPlayFromUri

void onPlayFromUri (MediaSession2 session, 
                MediaSession2.ControllerInfo controller, 
                Uri uri, 
                Bundle extras)

Called when a controller requested to play a specific media item represented by a URI through MediaController2.playFromUri(Uri, Bundle)

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

uri Uri: uri

extras Bundle: optional extra bundle

onPlaybackSpeedChanged

void onPlaybackSpeedChanged (MediaSession2 session, 
                MediaPlayerInterface player, 
                float speed)

Called to indicate that the playback speed has changed.

Parameters
session MediaSession2: the session for this event

player MediaPlayerInterface: the player for this event

speed float: the new playback speed.

onPlayerStateChanged

void onPlayerStateChanged (MediaSession2 session, 
                MediaPlayerInterface player, 
                int state)

Called to indicate that the state of the player has changed. See MediaPlayerInterface.getPlayerState() for polling the player state.

Parameters
session MediaSession2: the session for this event

player MediaPlayerInterface: the player for this event

state int: the new state of the player.

onPlaylistChanged

void onPlaylistChanged (MediaSession2 session, 
                MediaPlaylistAgent playlistAgent, 
                List<MediaItem2> list, 
                MediaMetadata2 metadata)

Called when a playlist is changed from the MediaPlaylistAgent.

This is called when the underlying agent has called MediaPlaylistAgent.PlaylistEventCallback.onPlaylistChanged(MediaPlaylistAgent, List, MediaMetadata2).

Parameters
session MediaSession2: the session for this event

playlistAgent MediaPlaylistAgent: playlist agent for this event

list List: new playlist

metadata MediaMetadata2: new metadata

onPlaylistMetadataChanged

void onPlaylistMetadataChanged (MediaSession2 session, 
                MediaPlaylistAgent playlistAgent, 
                MediaMetadata2 metadata)

Called when a playlist metadata is changed.

Parameters
session MediaSession2: the session for this event

playlistAgent MediaPlaylistAgent: playlist agent for this event

metadata MediaMetadata2: new metadata

onPrepareFromMediaId

void onPrepareFromMediaId (MediaSession2 session, 
                MediaSession2.ControllerInfo controller, 
                String mediaId, 
                Bundle extras)

Called when a controller requested to prepare for playing a specific mediaId through MediaController2.prepareFromMediaId(String, Bundle).

During the preparation, a session should not hold audio focus in order to allow other sessions play seamlessly. The state of playback should be updated to MediaPlayerInterface.PLAYER_STATE_PAUSED after the preparation is done.

The playback of the prepared content should start in the later calls of MediaSession2.play().

Override onPlayFromMediaId(MediaSession2, MediaSession2.ControllerInfo, String, Bundle) to handle requests for starting playback without preparation.

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

mediaId String: media id to prepare

extras Bundle: optional extra bundle

onPrepareFromSearch

void onPrepareFromSearch (MediaSession2 session, 
                MediaSession2.ControllerInfo controller, 
                String query, 
                Bundle extras)

Called when a controller requested to prepare playback from a search query through MediaController2.prepareFromSearch(String, Bundle).

An empty query indicates that the app may prepare any music. The implementation should attempt to make a smart choice about what to play.

The state of playback should be updated to MediaPlayerInterface.PLAYER_STATE_PAUSED after the preparation is done. The playback of the prepared content should start in the later calls of MediaSession2.play().

Override onPlayFromSearch(MediaSession2, MediaSession2.ControllerInfo, String, Bundle) to handle requests for starting playback without preparation.

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

query String: query string. Can be empty to indicate any suggested media

extras Bundle: optional extra bundle

onPrepareFromUri

void onPrepareFromUri (MediaSession2 session, 
                MediaSession2.ControllerInfo controller, 
                Uri uri, 
                Bundle extras)

Called when a controller requested to prepare a specific media item represented by a URI through MediaController2.prepareFromUri(Uri, Bundle).

During the preparation, a session should not hold audio focus in order to allow other sessions play seamlessly. The state of playback should be updated to MediaPlayerInterface.PLAYER_STATE_PAUSED after the preparation is done.

The playback of the prepared content should start in the later calls of MediaSession2.play().

Override onPlayFromUri(MediaSession2, MediaSession2.ControllerInfo, Uri, Bundle) to handle requests for starting playback without preparation.

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

uri Uri: uri

extras Bundle: optional extra bundle

onRepeatModeChanged

void onRepeatModeChanged (MediaSession2 session, 
                MediaPlaylistAgent playlistAgent, 
                int repeatMode)

Called when the repeat mode is changed.

Parameters
session MediaSession2: the session for this event

playlistAgent MediaPlaylistAgent: playlist agent for this event

repeatMode int: repeat mode

onRewind

void onRewind (MediaSession2 session, 
                MediaSession2.ControllerInfo controller)

Called when a controller called MediaController2.rewind()

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

onSeekCompleted

void onSeekCompleted (MediaSession2 session, 
                MediaPlayerInterface player, 
                long position)

Called to indicate that MediaSession2.seekTo(long) is completed.

Parameters
session MediaSession2: the session for this event.

player MediaPlayerInterface: the player that has completed seeking.

position long: the previous seeking request.

onSelectRoute

void onSelectRoute (MediaSession2 session, 
                MediaSession2.ControllerInfo controller, 
                Bundle route)

Called when a controller called MediaController2.selectRoute(Bundle).

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

route Bundle: The route bundle which may be from MediaRouteDescritor.asBundle().

onSetRating

void onSetRating (MediaSession2 session, 
                MediaSession2.ControllerInfo controller, 
                String mediaId, 
                Rating2 rating)

Called when a controller set rating of a media item through MediaController2.setRating(String, Rating2).

To allow setting user rating for a MediaItem2, the media item's metadata should have Rating2 with the key MediaMetadata2.METADATA_KEY_USER_RATING, in order to provide possible rating style for controller. Controller will follow the rating style.

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

mediaId String: media id from the controller

rating Rating2: new rating from the controller

onShuffleModeChanged

void onShuffleModeChanged (MediaSession2 session, 
                MediaPlaylistAgent playlistAgent, 
                int shuffleMode)

Called when the shuffle mode is changed.

Parameters
session MediaSession2: the session for this event

playlistAgent MediaPlaylistAgent: playlist agent for this event

shuffleMode int: repeat mode

onSubscribeRoutesInfo

void onSubscribeRoutesInfo (MediaSession2 session, 
                MediaSession2.ControllerInfo controller)

Called when a controller called MediaController2.subscribeRoutesInfo() Session app should notify the routes information by calling MediaSession2.notifyRoutesInfoChanged(ControllerInfo, List).

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information

onUnsubscribeRoutesInfo

void onUnsubscribeRoutesInfo (MediaSession2 session, 
                MediaSession2.ControllerInfo controller)

Called when a controller called MediaController2.unsubscribeRoutesInfo()

Parameters
session MediaSession2: the session for this event

controller MediaSession2.ControllerInfo: controller information