Register now for Android Dev Summit 2019!

ControllerCallback

abstract class ControllerCallback
kotlin.Any
   ↳ androidx.media2.session.MediaController.ControllerCallback

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

Summary

Public constructors

Interface for listening to change in activeness of the MediaSession.

Public methods

open Unit
onAllowedCommandsChanged(@NonNull controller: MediaController, @NonNull commands: SessionCommandGroup)

Called when the allowed commands are changed by session.

open Unit
onBufferingStateChanged(@NonNull controller: MediaController, @NonNull item: MediaItem, state: Int)

Called to report buffering events for a media item.

open Unit
onConnected(@NonNull controller: MediaController, @NonNull allowedCommands: SessionCommandGroup)

Called when the controller is successfully connected to the session.

open Unit
onCurrentMediaItemChanged(@NonNull controller: MediaController, @Nullable item: MediaItem?)

Called when the player's current item is changed.

open SessionResult
onCustomCommand(@NonNull controller: MediaController, @NonNull command: SessionCommand, @Nullable args: Bundle?)

Called when the session sent a custom command.

open Unit
onDisconnected(@NonNull controller: MediaController)

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

open Unit
onPlaybackCompleted(@NonNull controller: MediaController)

Called when the playback is completed.

open Unit

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

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

Called when playback speed is changed.

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

Called when the player state is changed.

open Unit
onPlaylistChanged(@NonNull controller: MediaController, @Nullable list: MutableList<MediaItem!>?, @Nullable metadata: MediaMetadata?)

Called when a playlist is changed.

open Unit
onPlaylistMetadataChanged(@NonNull controller: MediaController, @Nullable metadata: MediaMetadata?)

Called when a playlist metadata is changed.

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

Called when the repeat mode is changed.

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

Called to indicate that seeking is completed.

open Int
onSetCustomLayout(@NonNull controller: MediaController, @NonNull layout: MutableList<MediaSession.CommandButton!>)

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

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

Called when the shuffle mode is changed.

Public constructors

<init>

ControllerCallback()

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

Public methods

onAllowedCommandsChanged

open fun onAllowedCommandsChanged(@NonNull controller: MediaController, @NonNull commands: SessionCommandGroup): Unit

Called when the allowed commands are changed by session.

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

onBufferingStateChanged

open fun onBufferingStateChanged(@NonNull controller: MediaController, @NonNull item: MediaItem, state: Int): Unit

Called to report buffering events for a media item.

Use getBufferedPosition() for current buffering position.

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

onConnected

open fun onConnected(@NonNull controller: MediaController, @NonNull allowedCommands: SessionCommandGroup): Unit

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

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

onCurrentMediaItemChanged

open fun onCurrentMediaItemChanged(@NonNull controller: MediaController, @Nullable item: MediaItem?): Unit

Called when the player's current item is changed. It's also called after setPlaylist or setMediaItem.

When it's called, you should invalidate previous playback information and wait for later callbacks. Also, current, previous, and next media item indices may need to be updated.

Parameters
controller MediaController: the controller for this event
item MediaController: new current media item

onCustomCommand

@NonNull open fun onCustomCommand(@NonNull controller: MediaController, @NonNull command: SessionCommand, @Nullable args: Bundle?): SessionResult

Called when the session sent a custom command. Returns a SessionResult for session to get notification back. If the null is returned, SessionResult#RESULT_ERROR_UNKNOWN will be returned.

Default implementation returns SessionResult#RESULT_ERROR_NOT_SUPPORTED.

Parameters
controller MediaController: the controller for this event
command MediaController:
args MediaController:
Return
SessionResult: result of handling custom command

onDisconnected

open fun onDisconnected(@NonNull controller: MediaController): 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 MediaController: the controller for this event

onPlaybackCompleted

open fun onPlaybackCompleted(@NonNull controller: MediaController): Unit

Called when the playback is completed.

Parameters
controller MediaController: the controller for this event

onPlaybackInfoChanged

open fun onPlaybackInfoChanged(@NonNull controller: MediaController, @NonNull info: MediaController.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 MediaController: the controller for this event
info MediaController: new playback info

onPlaybackSpeedChanged

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

Called when playback speed is changed.

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

onPlayerStateChanged

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

Called when the player state is changed.

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

onPlaylistChanged

open fun onPlaylistChanged(@NonNull controller: MediaController, @Nullable list: MutableList<MediaItem!>?, @Nullable metadata: MediaMetadata?): Unit

Called when a playlist is changed. It's also called after setPlaylist or setMediaItem.

When it's called, current, previous, and next media item indices may need to be updated.

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

onPlaylistMetadataChanged

open fun onPlaylistMetadataChanged(@NonNull controller: MediaController, @Nullable metadata: MediaMetadata?): Unit

Called when a playlist metadata is changed.

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

onRepeatModeChanged

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

Called when the repeat mode is changed.

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

onSeekCompleted

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

Called to indicate that seeking is completed.

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

onSetCustomLayout

open fun onSetCustomLayout(@NonNull controller: MediaController, @NonNull layout: MutableList<MediaSession.CommandButton!>): Int

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

Can be called before onConnected(MediaController, SessionCommandGroup) is called.

Default implementation returns SessionResult#RESULT_ERROR_NOT_SUPPORTED.

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

onShuffleModeChanged

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

Called when the shuffle mode is changed.

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