MediaController.ControllerCallback

Added in 1.0.0
Deprecated in 1.3.0

public abstract class MediaController.ControllerCallback

Known direct subclasses
MediaBrowser.BrowserCallback

This class is deprecated.

androidx.media2 is deprecated.


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

Public methods

void

Called when the allowed commands are changed by session.

void
onBufferingStateChanged(
    @NonNull MediaController controller,
    @NonNull MediaItem item,
    int state
)

Called to report buffering events for a media item.

void
onConnected(
    @NonNull MediaController controller,
    @NonNull SessionCommandGroup allowedCommands
)

Called when the controller is successfully connected to the session.

void

Called when the current item is changed.

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

Called when the session sent a custom command.

void

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

void

Called when the playback is completed.

void

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

void
onPlaybackSpeedChanged(@NonNull MediaController controller, float speed)

Called when playback speed is changed.

void
onPlayerStateChanged(@NonNull MediaController controller, int state)

Called when the player state is changed.

void
onPlaylistChanged(
    @NonNull MediaController controller,
    @Nullable List<MediaItem> list,
    @Nullable MediaMetadata metadata
)

Called when a playlist is changed.

void

Called when a playlist metadata is changed.

void
onRepeatModeChanged(@NonNull MediaController controller, int repeatMode)

Called when the repeat mode is changed.

void
onSeekCompleted(@NonNull MediaController controller, long position)

Called to indicate that seeking is completed.

int

Called when the session set the custom layout through the setCustomLayout.

void
onShuffleModeChanged(
    @NonNull MediaController controller,
    int shuffleMode
)

Called when the shuffle mode is changed.

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

Called when the subtitle track has new subtitle data available.

void
onTrackDeselected(
    @NonNull MediaController controller,
    @NonNull SessionPlayer.TrackInfo trackInfo
)

Called when a track is deselected.

void
onTrackSelected(
    @NonNull MediaController controller,
    @NonNull SessionPlayer.TrackInfo trackInfo
)

Called when a track is selected.

void

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.

void
onVideoSizeChanged(
    @NonNull MediaController controller,
    @NonNull VideoSize videoSize
)

Called when video size is changed.

Public constructors

ControllerCallback

Added in 1.0.0
Deprecated in 1.3.0
public ControllerCallback()

Public methods

onAllowedCommandsChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onAllowedCommandsChanged(
    @NonNull MediaController controller,
    @NonNull SessionCommandGroup commands
)

Called when the allowed commands are changed by session.

Parameters
@NonNull MediaController controller

the controller for this event

@NonNull SessionCommandGroup commands

newly allowed commands

onBufferingStateChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onBufferingStateChanged(
    @NonNull MediaController controller,
    @NonNull MediaItem item,
    int state
)

Called to report buffering events for a media item.

Use getBufferedPosition for current buffering position.

Parameters
@NonNull MediaController controller

the controller for this event

@NonNull MediaItem item

the media item for which buffering is happening

int state

the new buffering state

onConnected

Added in 1.0.0
Deprecated in 1.3.0
public void onConnected(
    @NonNull MediaController controller,
    @NonNull SessionCommandGroup allowedCommands
)

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

Parameters
@NonNull MediaController controller

the controller for this event

@NonNull SessionCommandGroup allowedCommands

commands that's allowed by the session

onCurrentMediaItemChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onCurrentMediaItemChanged(
    @NonNull MediaController controller,
    @Nullable MediaItem item
)

Called when the current item is changed. It's also called after setPlaylist or setMediaItem. Also called when setMetadata 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
@NonNull MediaController controller

the controller for this event

@Nullable MediaItem item

new current media item

onCustomCommand

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull SessionResult onCustomCommand(
    @NonNull MediaController controller,
    @NonNull SessionCommand command,
    @Nullable Bundle args
)

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

Default implementation returns RESULT_ERROR_NOT_SUPPORTED.

Parameters
@NonNull MediaController controller

the controller for this event

@NonNull SessionCommand command
@Nullable Bundle args
Returns
@NonNull SessionResult

result of handling custom command

onDisconnected

Added in 1.0.0
Deprecated in 1.3.0
public void onDisconnected(@NonNull 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 close, so you can put clean up code here. You don't need to call close after this.

Parameters
@NonNull MediaController controller

the controller for this event

onPlaybackCompleted

Added in 1.0.0
Deprecated in 1.3.0
public void onPlaybackCompleted(@NonNull MediaController controller)

Called when the playback is completed.

Parameters
@NonNull MediaController controller

the controller for this event

onPlaybackInfoChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onPlaybackInfoChanged(
    @NonNull MediaController controller,
    @NonNull MediaController.PlaybackInfo info
)

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 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
@NonNull MediaController controller

the controller for this event

@NonNull MediaController.PlaybackInfo info

new playback info

onPlaybackSpeedChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onPlaybackSpeedChanged(@NonNull MediaController controller, float speed)

Called when playback speed is changed.

Parameters
@NonNull MediaController controller

the controller for this event

float speed

speed

onPlayerStateChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onPlayerStateChanged(@NonNull MediaController controller, int state)

Called when the player state is changed.

Parameters
@NonNull MediaController controller

the controller for this event

int state

the new player state

onPlaylistChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onPlaylistChanged(
    @NonNull MediaController controller,
    @Nullable List<MediaItem> list,
    @Nullable MediaMetadata metadata
)

Called when a playlist is changed. It's also called after setPlaylist or setMediaItem. Also called when setMetadata 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
@NonNull MediaController controller

the controller for this event

@Nullable List<MediaItem> list

new playlist

@Nullable MediaMetadata metadata

new metadata

onPlaylistMetadataChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onPlaylistMetadataChanged(
    @NonNull MediaController controller,
    @Nullable MediaMetadata metadata
)

Called when a playlist metadata is changed.

Parameters
@NonNull MediaController controller

the controller for this event

@Nullable MediaMetadata metadata

new metadata

onRepeatModeChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onRepeatModeChanged(@NonNull MediaController controller, int repeatMode)

Called when the repeat mode is changed.

Parameters
@NonNull MediaController controller

the controller for this event

int repeatMode

repeat mode

onSeekCompleted

Added in 1.0.0
Deprecated in 1.3.0
public void onSeekCompleted(@NonNull MediaController controller, long position)

Called to indicate that seeking is completed.

Parameters
@NonNull MediaController controller

the controller for this event

long position

the previous seeking request

onSetCustomLayout

Added in 1.0.0
Deprecated in 1.3.0
public int onSetCustomLayout(
    @NonNull MediaController controller,
    @NonNull List<MediaSession.CommandButton> layout
)

Called when the session set the custom layout through the setCustomLayout.

Can be called before onConnected is called.

Default implementation returns RESULT_ERROR_NOT_SUPPORTED.

Parameters
@NonNull MediaController controller

the controller for this event

@NonNull List<MediaSession.CommandButton> layout

onShuffleModeChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onShuffleModeChanged(
    @NonNull MediaController controller,
    int shuffleMode
)

Called when the shuffle mode is changed.

Parameters
@NonNull MediaController controller

the controller for this event

int shuffleMode

repeat mode

onSubtitleData

Added in 1.1.0
Deprecated in 1.3.0
public void onSubtitleData(
    @NonNull MediaController controller,
    @NonNull MediaItem item,
    @NonNull SessionPlayer.TrackInfo track,
    @NonNull SubtitleData data
)

Called when the subtitle track has new subtitle data available.

Parameters
@NonNull MediaController controller

the controller for this event

@NonNull MediaItem item

the MediaItem of this media item

@NonNull SessionPlayer.TrackInfo track

the track that has the subtitle data

@NonNull SubtitleData data

the subtitle data

onTrackDeselected

Added in 1.1.0
Deprecated in 1.3.0
public void onTrackDeselected(
    @NonNull MediaController controller,
    @NonNull 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
@NonNull MediaController controller

the controller for this event

@NonNull SessionPlayer.TrackInfo trackInfo

the deselected track

onTrackSelected

Added in 1.1.0
Deprecated in 1.3.0
public void onTrackSelected(
    @NonNull MediaController controller,
    @NonNull 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
@NonNull MediaController controller

the controller for this event

@NonNull SessionPlayer.TrackInfo trackInfo

the selected track

onTracksChanged

Added in 1.1.0
Deprecated in 1.3.0
public void onTracksChanged(
    @NonNull MediaController controller,
    @NonNull 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 selectTrack or deselectTrack.

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

Parameters
@NonNull MediaController controller

the controller for this event

@NonNull List<SessionPlayer.TrackInfo> tracks

the list of tracks. It can be empty.

onVideoSizeChanged

Added in 1.1.0
Deprecated in 1.3.0
public void onVideoSizeChanged(
    @NonNull MediaController controller,
    @NonNull VideoSize videoSize
)

Called when video size is changed.

Parameters
@NonNull MediaController controller

the controller for this event

@NonNull VideoSize videoSize

the size of video