public abstract class

MediaController.ControllerCallback

extends java.lang.Object

 java.lang.Object

↳androidx.media2.session.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 current item is changed.

public SessionResultonCustomCommand(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.

public voidonSubtitleData(MediaController controller, MediaItem item, SessionPlayer.TrackInfo track, SubtitleData data)

Called when the subtitle track has new subtitle data available.

public voidonTrackDeselected(MediaController controller, SessionPlayer.TrackInfo trackInfo)

Called when a track is deselected.

public voidonTracksChanged(MediaController controller, java.util.List<SessionPlayer.TrackInfo> tracks)

Called when the tracks of the current media item is changed such as 1) when tracks of a media item become available, 2) when new tracks are found during playback, or 3) when the current media item is changed.

public voidonTrackSelected(MediaController controller, SessionPlayer.TrackInfo trackInfo)

Called when a track is selected.

public voidonVideoSizeChanged(MediaController controller, MediaItem item, VideoSize videoSize)

public voidonVideoSizeChanged(MediaController controller, VideoSize videoSize)

Called when video size 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 BaseResult.RESULT_ERROR_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 SessionResult onCustomCommand(MediaController controller, SessionCommand command, Bundle args)

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

Default implementation returns BaseResult.RESULT_ERROR_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 current item is changed. It's also called after MediaController.setPlaylist(List, MediaMetadata) or MediaController.setMediaItem(String). Also called when MediaItem.setMetadata(MediaMetadata) is called on the current media item.

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 current media item

See also: MediaController.getPlaylist(), MediaController.getPlaylistMetadata()

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

Called when a playlist is changed. It's also called after MediaController.setPlaylist(List, MediaMetadata) or MediaController.setMediaItem(String). Also called when MediaItem.setMetadata(MediaMetadata) is called on a media item that is contained in the current playlist.

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

See also: MediaController.getPlaylist(), MediaController.getPlaylistMetadata()

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

public void onVideoSizeChanged(MediaController controller, MediaItem item, VideoSize videoSize)

Deprecated: Use MediaController.ControllerCallback.onVideoSizeChanged(MediaController, VideoSize) instead.

public void onVideoSizeChanged(MediaController controller, VideoSize videoSize)

Called when video size is changed.

Parameters:

controller: the controller for this event
videoSize: the size of video

public void onTracksChanged(MediaController controller, java.util.List<SessionPlayer.TrackInfo> tracks)

Called when the tracks of the current media item is changed such as 1) when tracks of a media item become available, 2) when new tracks are found during playback, or 3) when the current media item is changed.

When it's called, you should invalidate previous track information and use the new tracks to call MediaController.ControllerCallback or MediaController.ControllerCallback.

The types of tracks supported may vary based on player implementation.

Parameters:

controller: the controller for this event
tracks: the list of tracks. It can be empty.

See also: SessionPlayer.TrackInfo.MEDIA_TRACK_TYPE_VIDEO, SessionPlayer.TrackInfo.MEDIA_TRACK_TYPE_AUDIO, SessionPlayer.TrackInfo.MEDIA_TRACK_TYPE_SUBTITLE, SessionPlayer.TrackInfo.MEDIA_TRACK_TYPE_METADATA

public void onTrackSelected(MediaController controller, SessionPlayer.TrackInfo trackInfo)

Called when a track is selected.

The types of tracks supported may vary based on player implementation, but generally one track will be selected for each track type.

Parameters:

controller: the controller for this event
trackInfo: the selected track

See also: SessionPlayer.TrackInfo.MEDIA_TRACK_TYPE_VIDEO, SessionPlayer.TrackInfo.MEDIA_TRACK_TYPE_AUDIO, SessionPlayer.TrackInfo.MEDIA_TRACK_TYPE_SUBTITLE, SessionPlayer.TrackInfo.MEDIA_TRACK_TYPE_METADATA

public void onTrackDeselected(MediaController controller, SessionPlayer.TrackInfo trackInfo)

Called when a track is deselected.

The types of tracks supported may vary based on player implementation, but generally a track should already be selected in order to be deselected and audio and video tracks should not be deselected.

Parameters:

controller: the controller for this event
trackInfo: the deselected track

See also: SessionPlayer.TrackInfo.MEDIA_TRACK_TYPE_VIDEO, SessionPlayer.TrackInfo.MEDIA_TRACK_TYPE_AUDIO, SessionPlayer.TrackInfo.MEDIA_TRACK_TYPE_SUBTITLE, SessionPlayer.TrackInfo.MEDIA_TRACK_TYPE_METADATA

public void onSubtitleData(MediaController controller, MediaItem item, SessionPlayer.TrackInfo track, SubtitleData data)

Called when the subtitle track has new subtitle data available.

Parameters:

controller: the controller for this event
item: the MediaItem of this media item
track: the track that has the subtitle data
data: the subtitle data