public abstract class

MediaController.ControllerCallback

extends java.lang.Object

 java.lang.Object

↳androidx.media2.MediaController.ControllerCallback

Subclasses:

MediaBrowser.BrowserCallback

Overview

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

Summary

Constructors
publicControllerCallback()

Methods
public voidonAllowedCommandsChanged(MediaController controller, SessionCommandGroup commands)

Called when the allowed commands are changed by session.

public voidonBufferingStateChanged(MediaController controller, MediaItem item, int state)

Called to report buffering events for a media item.

public voidonConnected(MediaController controller, SessionCommandGroup allowedCommands)

Called when the controller is successfully connected to the session.

public voidonCurrentMediaItemChanged(MediaController controller, MediaItem item)

Called when the player's currently playing item is changed

public MediaController.ControllerResultonCustomCommand(MediaController controller, SessionCommand command, Bundle args)

Called when the session sent a custom command.

public voidonDisconnected(MediaController controller)

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

public voidonPlaybackCompleted(MediaController controller)

Called when the playback is completed.

public voidonPlaybackInfoChanged(MediaController controller, MediaController.PlaybackInfo info)

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

public voidonPlaybackSpeedChanged(MediaController controller, float speed)

Called when playback speed is changed.

public voidonPlayerStateChanged(MediaController controller, int state)

Called when the player state is changed.

public voidonPlaylistChanged(MediaController controller, java.util.List<MediaItem> list, MediaMetadata metadata)

Called when a playlist is changed.

public voidonPlaylistMetadataChanged(MediaController controller, MediaMetadata metadata)

Called when a playlist metadata is changed.

public voidonRepeatModeChanged(MediaController controller, int repeatMode)

Called when the repeat mode is changed.

public voidonSeekCompleted(MediaController controller, long position)

Called to indicate that seeking is completed.

public intonSetCustomLayout(MediaController controller, java.util.List<MediaSession.CommandButton> layout)

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

public voidonShuffleModeChanged(MediaController controller, int shuffleMode)

Called when the shuffle mode is changed.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public ControllerCallback()

Methods

public void onConnected(MediaController controller, SessionCommandGroup allowedCommands)

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

Parameters:

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

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

Parameters:

controller: the controller for this event

public int onSetCustomLayout(MediaController controller, java.util.List<MediaSession.CommandButton> layout)

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

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

Default implementation returns RESULT_CODE_NOT_SUPPORTED.

Parameters:

controller: the controller for this event
layout:

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

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

Interoperability: When connected to android.support.v4.media.session.MediaSessionCompat, this may be called when the session changes playback info by calling setPlaybackToLocal or setPlaybackToRemote}. 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: the controller for this event
info: new playback info

public void onAllowedCommandsChanged(MediaController controller, SessionCommandGroup commands)

Called when the allowed commands are changed by session.

Parameters:

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

public MediaController.ControllerResult onCustomCommand(MediaController controller, SessionCommand command, Bundle args)

Called when the session sent a custom command. Returns a MediaController.ControllerResult for session to get notification back. If the null is returned, RESULT_CODE_UNKNOWN_ERROR will be returned.

Default implementation returns RESULT_CODE_NOT_SUPPORTED.

Parameters:

controller: the controller for this event
command:
args:

Returns:

result of handling custom command

public void onPlayerStateChanged(MediaController controller, int state)

Called when the player state is changed.

Parameters:

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

public void onPlaybackSpeedChanged(MediaController controller, float speed)

Called when playback speed is changed.

Parameters:

controller: the controller for this event
speed: speed

public void onBufferingStateChanged(MediaController controller, MediaItem item, int state)

Called to report buffering events for a media item.

Use MediaController.getBufferedPosition() for current buffering position.

Parameters:

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

public void onSeekCompleted(MediaController controller, long position)

Called to indicate that seeking is completed.

Parameters:

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

public void onCurrentMediaItemChanged(MediaController controller, MediaItem 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. Also, current, previous, and next media item indices may need to be updated.

Parameters:

controller: the controller for this event
item: new item

public void onPlaylistChanged(MediaController controller, java.util.List<MediaItem> list, MediaMetadata metadata)

Called when a playlist is changed.

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

Parameters:

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

public void onPlaylistMetadataChanged(MediaController controller, MediaMetadata metadata)

Called when a playlist metadata is changed.

Parameters:

controller: the controller for this event
metadata: new metadata

public void onShuffleModeChanged(MediaController controller, int shuffleMode)

Called when the shuffle mode is changed.

Parameters:

controller: the controller for this event
shuffleMode: repeat mode

See also: SessionPlayer.SHUFFLE_MODE_NONE, SessionPlayer.SHUFFLE_MODE_ALL, SessionPlayer.SHUFFLE_MODE_GROUP

public void onRepeatModeChanged(MediaController controller, int repeatMode)

Called when the repeat mode is changed.

Parameters:

controller: the controller for this event
repeatMode: repeat mode

See also: SessionPlayer.REPEAT_MODE_NONE, SessionPlayer.REPEAT_MODE_ONE, SessionPlayer.REPEAT_MODE_ALL, SessionPlayer.REPEAT_MODE_GROUP

public void onPlaybackCompleted(MediaController controller)

Called when the playback is completed.

Parameters:

controller: the controller for this event