SessionCallback

abstract class SessionCallback
kotlin.Any
   ↳ 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

Public methods
open Unit

Called when a controller called MediaController2#rewind()

open Unit

Called when the player is prepared, i.

open Unit

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

open Unit

Called when a controller called MediaController2#unsubscribeRoutesInfo()

open Unit

Called when a controller called MediaController2#fastForward()

open Unit

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

open Unit

Called when a playlist metadata is changed.

open Unit

Called to report buffering events for a data source.

open Unit
onShuffleModeChanged(session: MediaSession2, playlistAgent: MediaPlaylistAgent, shuffleMode: Int)

Called when the shuffle mode is changed.

open Unit

Called when a controller is disconnected

open Unit
onPrepareFromMediaId(session: MediaSession2, controller: MediaSession2.ControllerInfo, mediaId: String, extras: Bundle?)

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

open Unit

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

open SessionCommandGroup2?

Called when a controller is created for this session.

open Unit
onRepeatModeChanged(session: MediaSession2, playlistAgent: MediaPlaylistAgent, repeatMode: Int)

Called when the repeat mode is changed.

open Boolean

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.

open Unit
onCustomCommand(session: MediaSession2, controller: MediaSession2.ControllerInfo, customCommand: SessionCommand2, args: Bundle?, cb: ResultReceiver?)

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

open Unit
onPlaylistChanged(session: MediaSession2, playlistAgent: MediaPlaylistAgent, list: MutableList<MediaItem2!>, metadata: MediaMetadata2?)

Called when a playlist is changed from the MediaPlaylistAgent.

open Unit
onSeekCompleted(session: MediaSession2, player: MediaPlayerInterface, position: Long)

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

open Unit
onPrepareFromSearch(session: MediaSession2, controller: MediaSession2.ControllerInfo, query: String, extras: Bundle?)

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

open Unit
onPlayFromMediaId(session: MediaSession2, controller: MediaSession2.ControllerInfo, mediaId: String, extras: Bundle?)

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

open Unit

Called when the player's current playing item is changed

open Unit
onSetRating(session: MediaSession2, controller: MediaSession2.ControllerInfo, mediaId: String, rating: Rating2)

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

open Unit
onPlayFromSearch(session: MediaSession2, controller: MediaSession2.ControllerInfo, query: String, extras: Bundle?)

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

open Unit
onPlayFromUri(session: MediaSession2, controller: MediaSession2.ControllerInfo, uri: Uri, extras: Bundle?)

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

open Unit
onPrepareFromUri(session: MediaSession2, controller: MediaSession2.ControllerInfo, uri: Uri, extras: Bundle?)

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

open Unit

Called to indicate that the playback speed has changed.

Public constructors

<init>

SessionCallback()

Public methods

onRewind

open fun onRewind(session: MediaSession2, controller: MediaSession2.ControllerInfo!): Unit

Called when a controller called MediaController2#rewind()

Parameters
session MediaSession2: the session for this event
controller MediaSession2: controller information

onMediaPrepared

open fun onMediaPrepared(session: MediaSession2, player: MediaPlayerInterface, item: MediaItem2): Unit

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 MediaSession2: the player for this event
item MediaSession2: the media item for which buffering is happening

onSubscribeRoutesInfo

open fun onSubscribeRoutesInfo(session: MediaSession2, controller: MediaSession2.ControllerInfo): Unit

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: controller information

onUnsubscribeRoutesInfo

open fun onUnsubscribeRoutesInfo(session: MediaSession2, controller: MediaSession2.ControllerInfo): Unit

Called when a controller called MediaController2#unsubscribeRoutesInfo()

Parameters
session MediaSession2: the session for this event
controller MediaSession2: controller information

onFastForward

open fun onFastForward(session: MediaSession2, controller: MediaSession2.ControllerInfo!): Unit

Called when a controller called MediaController2#fastForward()

Parameters
session MediaSession2: the session for this event
controller MediaSession2: controller information

onPlayerStateChanged

open fun onPlayerStateChanged(session: MediaSession2, player: MediaPlayerInterface, state: Int): Unit

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 MediaSession2: the player for this event
state MediaSession2: the new state of the player.

onPlaylistMetadataChanged

open fun onPlaylistMetadataChanged(session: MediaSession2, playlistAgent: MediaPlaylistAgent, metadata: MediaMetadata2?): Unit

Called when a playlist metadata is changed.

Parameters
session MediaSession2: the session for this event
playlistAgent MediaSession2: playlist agent for this event
metadata MediaSession2: new metadata

onBufferingStateChanged

open fun onBufferingStateChanged(session: MediaSession2, player: MediaPlayerInterface, item: MediaItem2, state: Int): Unit

Called to report buffering events for a data source.

Parameters
session MediaSession2: the session for this event
player MediaSession2: the player for this event
item MediaSession2: the media item for which buffering is happening.
state MediaSession2: the new buffering state.

onShuffleModeChanged

open fun onShuffleModeChanged(session: MediaSession2, playlistAgent: MediaPlaylistAgent, shuffleMode: Int): Unit

Called when the shuffle mode is changed.

Parameters
session MediaSession2: the session for this event
playlistAgent MediaSession2: playlist agent for this event
shuffleMode MediaSession2: repeat mode

onDisconnected

open fun onDisconnected(session: MediaSession2, controller: MediaSession2.ControllerInfo): Unit

Called when a controller is disconnected

Parameters
session MediaSession2: the session for this event
controller MediaSession2: controller information

onPrepareFromMediaId

open fun onPrepareFromMediaId(session: MediaSession2, controller: MediaSession2.ControllerInfo, mediaId: String, extras: Bundle?): Unit

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 to handle requests for starting playback without preparation.

Parameters
session MediaSession2: the session for this event
controller MediaSession2: controller information
mediaId MediaSession2: media id to prepare
extras MediaSession2: optional extra bundle

onSelectRoute

open fun onSelectRoute(session: MediaSession2, controller: MediaSession2.ControllerInfo, route: Bundle): Unit

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

Parameters
session MediaSession2: the session for this event
controller MediaSession2: controller information
route MediaSession2: The route bundle which may be from MediaRouteDescritor.asBundle().

onConnect

open fun onConnect(session: MediaSession2, controller: MediaSession2.ControllerInfo): SessionCommandGroup2?

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: controller information.
Return
SessionCommandGroup2?: allowed commands. Can be null to reject connection.

onRepeatModeChanged

open fun onRepeatModeChanged(session: MediaSession2, playlistAgent: MediaPlaylistAgent, repeatMode: Int): Unit

Called when the repeat mode is changed.

Parameters
session MediaSession2: the session for this event
playlistAgent MediaSession2: playlist agent for this event
repeatMode MediaSession2: repeat mode

onCommandRequest

open fun onCommandRequest(session: MediaSession2, controller: MediaSession2.ControllerInfo, command: SessionCommand2): Boolean

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: controller information.
command MediaSession2: a command. This method will be called for every single command.
Return
Boolean: true if you want to accept incoming command. false otherwise.

See Also

onCustomCommand

open fun onCustomCommand(session: MediaSession2, controller: MediaSession2.ControllerInfo, customCommand: SessionCommand2, args: Bundle?, cb: ResultReceiver?): Unit

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

Parameters
session MediaSession2: the session for this event
controller MediaSession2: controller information
customCommand MediaSession2: custom command.
args MediaSession2: optional arguments
cb MediaSession2: optional result receiver

onPlaylistChanged

open fun onPlaylistChanged(session: MediaSession2, playlistAgent: MediaPlaylistAgent, list: MutableList<MediaItem2!>, metadata: MediaMetadata2?): Unit

Called when a playlist is changed from the MediaPlaylistAgent.

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

Parameters
session MediaSession2: the session for this event
playlistAgent MediaSession2: playlist agent for this event
list MediaSession2: new playlist
metadata MediaSession2: new metadata

onSeekCompleted

open fun onSeekCompleted(session: MediaSession2, player: MediaPlayerInterface, position: Long): Unit

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

Parameters
session MediaSession2: the session for this event.
player MediaSession2: the player that has completed seeking.
position MediaSession2: the previous seeking request.

See Also

onPrepareFromSearch

open fun onPrepareFromSearch(session: MediaSession2, controller: MediaSession2.ControllerInfo, query: String, extras: Bundle?): Unit

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 to handle requests for starting playback without preparation.

Parameters
session MediaSession2: the session for this event
controller MediaSession2: controller information
query MediaSession2: query string. Can be empty to indicate any suggested media
extras MediaSession2: optional extra bundle

onPlayFromMediaId

open fun onPlayFromMediaId(session: MediaSession2, controller: MediaSession2.ControllerInfo, mediaId: String, extras: Bundle?): Unit

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: controller information
mediaId MediaSession2: media id
extras MediaSession2: optional extra bundle

onCurrentMediaItemChanged

open fun onCurrentMediaItemChanged(session: MediaSession2, player: MediaPlayerInterface, item: MediaItem2?): Unit

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 MediaSession2: the player for this event
item MediaSession2: new item

onSetRating

open fun onSetRating(session: MediaSession2, controller: MediaSession2.ControllerInfo, mediaId: String, rating: Rating2): Unit

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: controller information
mediaId MediaSession2: media id from the controller
rating MediaSession2: new rating from the controller

onPlayFromSearch

open fun onPlayFromSearch(session: MediaSession2, controller: MediaSession2.ControllerInfo, query: String, extras: Bundle?): Unit

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: controller information
query MediaSession2: query string. Can be empty to indicate any suggested media
extras MediaSession2: optional extra bundle

onPlayFromUri

open fun onPlayFromUri(session: MediaSession2, controller: MediaSession2.ControllerInfo, uri: Uri, extras: Bundle?): Unit

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: controller information
uri MediaSession2: uri
extras MediaSession2: optional extra bundle

onPrepareFromUri

open fun onPrepareFromUri(session: MediaSession2, controller: MediaSession2.ControllerInfo, uri: Uri, extras: Bundle?): Unit

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 to handle requests for starting playback without preparation.

Parameters
session MediaSession2: the session for this event
controller MediaSession2: controller information
uri MediaSession2: uri
extras MediaSession2: optional extra bundle

onPlaybackSpeedChanged

open fun onPlaybackSpeedChanged(session: MediaSession2, player: MediaPlayerInterface, speed: Float): Unit

Called to indicate that the playback speed has changed.

Parameters
session MediaSession2: the session for this event
player MediaSession2: the player for this event
speed MediaSession2: the new playback speed.