Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

ControllerCallback

abstract class ControllerCallback
kotlin.Any
   ↳ androidx.media2.MediaController2.ControllerCallback

Interface for listening to change in activeness of the MediaSession2. It's active if and only if it has set a player.

Summary

Public constructors

Interface for listening to change in activeness of the MediaSession2.

Public methods
open Unit

Called when the session has changed anything related with the PlaybackInfo.

open Unit
onRepeatModeChanged(@NonNull controller: MediaController2, repeatMode: Int)

Called when the repeat mode is changed.

open Unit
onAllowedCommandsChanged(@NonNull controller: MediaController2, @NonNull commands: SessionCommandGroup2)

Called when the allowed commands are changed by session.

open Unit
onCustomCommand(@NonNull controller: MediaController2, @NonNull command: SessionCommand2, @Nullable args: Bundle?, @Nullable receiver: ResultReceiver?)

Called when the session sent a custom command.

open Unit
onPlaylistChanged(@NonNull controller: MediaController2, @NonNull list: MutableList<MediaItem2!>, @Nullable metadata: MediaMetadata2?)

Called when a playlist is changed.

open Unit
onRoutesInfoChanged(@NonNull controller: MediaController2, @Nullable routes: MutableList<Bundle!>?)

Called when a property of the indicated media route has changed.

open Unit

Called when the session set the custom layout through the MediaSession2#setCustomLayout(ControllerInfo, List).

open Unit
onSeekCompleted(@NonNull controller: MediaController2, position: Long)

Called to indicate that seeking is completed.

open Unit
onPlayerStateChanged(@NonNull controller: MediaController2, state: Int)

Called when the player state is changed.

open Unit
onCurrentMediaItemChanged(@NonNull controller: MediaController2, @Nullable item: MediaItem2?)

Called when the player's currently playing item is changed

open Unit
onPlaylistMetadataChanged(@NonNull controller: MediaController2, @Nullable metadata: MediaMetadata2?)

Called when a playlist metadata is changed.

open Unit
onBufferingStateChanged(@NonNull controller: MediaController2, @NonNull item: MediaItem2, state: Int)

Called to report buffering events for a data source.

open Unit
onConnected(@NonNull controller: MediaController2, @NonNull allowedCommands: SessionCommandGroup2)

Called when the controller is successfully connected to the session.

open Unit
onShuffleModeChanged(@NonNull controller: MediaController2, shuffleMode: Int)

Called when the shuffle mode is changed.

open Unit
onDisconnected(@NonNull controller: MediaController2)

Called when the session refuses the controller or the controller is disconnected from the session.

open Unit
onPlaybackSpeedChanged(@NonNull controller: MediaController2, speed: Float)

Called when playback speed is changed.

open Unit
onError(@NonNull controller: MediaController2, errorCode: Int, @Nullable extras: Bundle?)

Called when a error from

Public constructors

<init>

ControllerCallback()

Interface for listening to change in activeness of the MediaSession2. It's active if and only if it has set a player.

Public methods

onPlaybackInfoChanged

open fun onPlaybackInfoChanged(@NonNull controller: MediaController2, @NonNull info: MediaController2.PlaybackInfo): Unit

Called when the session has changed anything related with the PlaybackInfo.

Interoperability: When connected to android.support.v4.media.session.MediaSessionCompat, this may be called when the session changes playback info by calling android.support.v4.media.session.MediaSessionCompat#setPlaybackToLocal(int) or android.support.v4.media.session.MediaSessionCompat#setPlaybackToRemote( * VolumeProviderCompat)}. Specifically:

  • Prior to API 21, this will always be called whenever any of those two methods is called.
  • From API 21 to 22, this is called only when the playback type is changed from local to remote (i.e. not from remote to local).
  • From API 23, this is called only when the playback type is changed.
Parameters
controller MediaController2: the controller for this event
info MediaController2: new playback info

onRepeatModeChanged

open fun onRepeatModeChanged(@NonNull controller: MediaController2, repeatMode: Int): Unit

Called when the repeat mode is changed.

Parameters
controller MediaController2: the controller for this event
repeatMode MediaController2: repeat mode

onAllowedCommandsChanged

open fun onAllowedCommandsChanged(@NonNull controller: MediaController2, @NonNull commands: SessionCommandGroup2): Unit

Called when the allowed commands are changed by session.

Parameters
controller MediaController2: the controller for this event
commands MediaController2: newly allowed commands

onCustomCommand

open fun onCustomCommand(@NonNull controller: MediaController2, @NonNull command: SessionCommand2, @Nullable args: Bundle?, @Nullable receiver: ResultReceiver?): Unit

Called when the session sent a custom command.

Parameters
controller MediaController2: the controller for this event
command MediaController2:
args MediaController2:
receiver MediaController2:

onPlaylistChanged

open fun onPlaylistChanged(@NonNull controller: MediaController2, @NonNull list: MutableList<MediaItem2!>, @Nullable metadata: MediaMetadata2?): Unit

Called when a playlist is changed.

Parameters
controller MediaController2: the controller for this event
list MediaController2: new playlist
metadata MediaController2: new metadata

onRoutesInfoChanged

open fun onRoutesInfoChanged(@NonNull controller: MediaController2, @Nullable routes: MutableList<Bundle!>?): Unit

Called when a property of the indicated media route has changed.

Parameters
controller MediaController2: the controller for this event
routes MediaController2: The list of Bundle from RouteInfo.

onCustomLayoutChanged

open fun onCustomLayoutChanged(@NonNull controller: MediaController2, @NonNull layout: MutableList<MediaSession2.CommandButton!>): Unit

Called when the session set the custom layout through the MediaSession2#setCustomLayout(ControllerInfo, List).

Can be called before onConnected(MediaController2, SessionCommandGroup2) is called.

Parameters
controller MediaController2: the controller for this event
layout MediaController2:

onSeekCompleted

open fun onSeekCompleted(@NonNull controller: MediaController2, position: Long): Unit

Called to indicate that seeking is completed.

Parameters
controller MediaController2: the controller for this event.
position MediaController2: the previous seeking request.

onPlayerStateChanged

open fun onPlayerStateChanged(@NonNull controller: MediaController2, state: Int): Unit

Called when the player state is changed.

Parameters
controller MediaController2: the controller for this event
state MediaController2: the new player state

onCurrentMediaItemChanged

open fun onCurrentMediaItemChanged(@NonNull controller: MediaController2, @Nullable item: MediaItem2?): Unit

Called when the player's currently playing item is changed

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

Parameters
controller MediaController2: the controller for this event
item MediaController2: new item

onPlaylistMetadataChanged

open fun onPlaylistMetadataChanged(@NonNull controller: MediaController2, @Nullable metadata: MediaMetadata2?): Unit

Called when a playlist metadata is changed.

Parameters
controller MediaController2: the controller for this event
metadata MediaController2: new metadata

onBufferingStateChanged

open fun onBufferingStateChanged(@NonNull controller: MediaController2, @NonNull item: MediaItem2, state: Int): Unit

Called to report buffering events for a data source.

Use getBufferedPosition() for current buffering position.

Parameters
controller MediaController2: the controller for this event
item MediaController2: the media item for which buffering is happening.
state MediaController2: the new buffering state.

onConnected

open fun onConnected(@NonNull controller: MediaController2, @NonNull allowedCommands: SessionCommandGroup2): Unit

Called when the controller is successfully connected to the session. The controller becomes available afterwards.

Parameters
controller MediaController2: the controller for this event
allowedCommands MediaController2: commands that's allowed by the session.

onShuffleModeChanged

open fun onShuffleModeChanged(@NonNull controller: MediaController2, shuffleMode: Int): Unit

Called when the shuffle mode is changed.

Parameters
controller MediaController2: the controller for this event
shuffleMode MediaController2: repeat mode

onDisconnected

open fun onDisconnected(@NonNull controller: MediaController2): Unit

Called when the session refuses the controller or the controller is disconnected from the session. The controller becomes unavailable afterwards and the callback wouldn't be called.

It will be also called after the close(), so you can put clean up code here. You don't need to call close() after this.

Parameters
controller MediaController2: the controller for this event

onPlaybackSpeedChanged

open fun onPlaybackSpeedChanged(@NonNull controller: MediaController2, speed: Float): Unit

Called when playback speed is changed.

Parameters
controller MediaController2: the controller for this event
speed MediaController2: speed

onError

open fun onError(@NonNull controller: MediaController2, errorCode: Int, @Nullable extras: Bundle?): Unit

Called when a error from

Parameters
controller MediaController2: the controller for this event
errorCode MediaController2: error code
extras MediaController2: extra information