MediaController2.ControllerCallback

public static abstract class MediaController2.ControllerCallback
extends Object

java.lang.Object
   ↳ 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

MediaController2.ControllerCallback()

Public methods

void onAllowedCommandsChanged(MediaController2 controller, SessionCommandGroup2 commands)

Called when the allowed commands are changed by session.

void onBufferingStateChanged(MediaController2 controller, MediaItem2 item, int state)

Called to report buffering events for a data source.

void onConnected(MediaController2 controller, SessionCommandGroup2 allowedCommands)

Called when the controller is successfully connected to the session.

void onCurrentMediaItemChanged(MediaController2 controller, MediaItem2 item)

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.

void onCustomCommand(MediaController2 controller, SessionCommand2 command, Bundle args, ResultReceiver receiver)

Called when the session sent a custom command.

void onCustomLayoutChanged(MediaController2 controller, List<MediaSession2.CommandButton> layout)

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

void onDisconnected(MediaController2 controller)

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

void onError(MediaController2 controller, int errorCode, Bundle extras)

Called when a error from

void onPlaybackInfoChanged(MediaController2 controller, MediaController2.PlaybackInfo info)

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

void onPlaybackSpeedChanged(MediaController2 controller, float speed)

Called when playback speed is changed.

void onPlayerStateChanged(MediaController2 controller, int state)

Called when the player state is changed.

void onPlaylistChanged(MediaController2 controller, List<MediaItem2> list, MediaMetadata2 metadata)

Called when a playlist is changed.

void onPlaylistMetadataChanged(MediaController2 controller, MediaMetadata2 metadata)

Called when a playlist metadata is changed.

void onRepeatModeChanged(MediaController2 controller, int repeatMode)

Called when the repeat mode is changed.

void onRoutesInfoChanged(MediaController2 controller, List<Bundle> routes)

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

void onSeekCompleted(MediaController2 controller, long position)

Called to indicate that seeking is completed.

void onShuffleModeChanged(MediaController2 controller, int shuffleMode)

Called when the shuffle mode is changed.

Inherited methods

Public constructors

MediaController2.ControllerCallback

public MediaController2.ControllerCallback ()

Public methods

onAllowedCommandsChanged

public void onAllowedCommandsChanged (MediaController2 controller, 
                SessionCommandGroup2 commands)

Called when the allowed commands are changed by session.

Parameters
controller MediaController2: the controller for this event

commands SessionCommandGroup2: newly allowed commands

onBufferingStateChanged

public void onBufferingStateChanged (MediaController2 controller, 
                MediaItem2 item, 
                int state)

Called to report buffering events for a data source.

Use MediaController2.getBufferedPosition() for current buffering position.

Parameters
controller MediaController2: the controller for this event

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

state int: the new buffering state.

onConnected

public void onConnected (MediaController2 controller, 
                SessionCommandGroup2 allowedCommands)

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

Parameters
controller MediaController2: the controller for this event

allowedCommands SessionCommandGroup2: commands that's allowed by the session.

onCurrentMediaItemChanged

public void onCurrentMediaItemChanged (MediaController2 controller, 
                MediaItem2 item)

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 MediaItem2: new item

onCustomCommand

public void onCustomCommand (MediaController2 controller, 
                SessionCommand2 command, 
                Bundle args, 
                ResultReceiver receiver)

Called when the session sent a custom command.

Parameters
controller MediaController2: the controller for this event

onCustomLayoutChanged

public void onCustomLayoutChanged (MediaController2 controller, 
                List<MediaSession2.CommandButton> layout)

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

onDisconnected

public void onDisconnected (MediaController2 controller)

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 MediaController2.close(), so you can put clean up code here. You don't need to call MediaController2.close() after this.

Parameters
controller MediaController2: the controller for this event

onError

public void onError (MediaController2 controller, 
                int errorCode, 
                Bundle extras)

Called when a error from

Parameters
controller MediaController2: the controller for this event

errorCode int: error code

extras Bundle: extra information

onPlaybackInfoChanged

public void onPlaybackInfoChanged (MediaController2 controller, 
                MediaController2.PlaybackInfo info)

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

Interoperability: When connected to MediaSessionCompat, this may be called when the session changes playback info by calling MediaSessionCompat.setPlaybackToLocal(int) or 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.PlaybackInfo: new playback info

onPlaybackSpeedChanged

public void onPlaybackSpeedChanged (MediaController2 controller, 
                float speed)

Called when playback speed is changed.

Parameters
controller MediaController2: the controller for this event

speed float: speed

onPlayerStateChanged

public void onPlayerStateChanged (MediaController2 controller, 
                int state)

Called when the player state is changed.

Parameters
controller MediaController2: the controller for this event

state int: the new player state

onPlaylistChanged

public void onPlaylistChanged (MediaController2 controller, 
                List<MediaItem2> list, 
                MediaMetadata2 metadata)

Called when a playlist is changed.

Parameters
controller MediaController2: the controller for this event

list List: new playlist

metadata MediaMetadata2: new metadata

onPlaylistMetadataChanged

public void onPlaylistMetadataChanged (MediaController2 controller, 
                MediaMetadata2 metadata)

Called when a playlist metadata is changed.

Parameters
controller MediaController2: the controller for this event

metadata MediaMetadata2: new metadata

onRepeatModeChanged

public void onRepeatModeChanged (MediaController2 controller, 
                int repeatMode)

Called when the repeat mode is changed.

Parameters
controller MediaController2: the controller for this event

repeatMode int: repeat mode

onRoutesInfoChanged

public void onRoutesInfoChanged (MediaController2 controller, 
                List<Bundle> routes)

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

Parameters
controller MediaController2: the controller for this event

routes List: The list of Bundle from RouteInfo.

onSeekCompleted

public void onSeekCompleted (MediaController2 controller, 
                long position)

Called to indicate that seeking is completed.

Parameters
controller MediaController2: the controller for this event.

position long: the previous seeking request.

onShuffleModeChanged

public void onShuffleModeChanged (MediaController2 controller, 
                int shuffleMode)

Called when the shuffle mode is changed.

Parameters
controller MediaController2: the controller for this event

shuffleMode int: repeat mode