MediaController.ControllerCallback

Added in 1.0.0
Deprecated in 1.3.0

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 functions

Unit
onAllowedCommandsChanged(
    controller: MediaController,
    commands: SessionCommandGroup
)

Called when the allowed commands are changed by session.

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

Called to report buffering events for a media item.

Unit
onConnected(
    controller: MediaController,
    allowedCommands: SessionCommandGroup
)

Called when the controller is successfully connected to the session.

Unit

Called when the current item is changed.

SessionResult
onCustomCommand(
    controller: MediaController,
    command: SessionCommand,
    args: Bundle?
)

Called when the session sent a custom command.

Unit

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

Unit

Called when the playback is completed.

Unit

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

Unit

Called when playback speed is changed.

Unit
onPlayerStateChanged(controller: MediaController, state: Int)

Called when the player state is changed.

Unit
onPlaylistChanged(
    controller: MediaController,
    list: (Mutable)List<MediaItem!>?,
    metadata: MediaMetadata?
)

Called when a playlist is changed.

Unit
onPlaylistMetadataChanged(
    controller: MediaController,
    metadata: MediaMetadata?
)

Called when a playlist metadata is changed.

Unit
onRepeatModeChanged(controller: MediaController, repeatMode: Int)

Called when the repeat mode is changed.

Unit
onSeekCompleted(controller: MediaController, position: Long)

Called to indicate that seeking is completed.

Int
onSetCustomLayout(
    controller: MediaController,
    layout: (Mutable)List<MediaSession.CommandButton!>
)

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

Unit
onShuffleModeChanged(controller: MediaController, shuffleMode: Int)

Called when the shuffle mode is changed.

Unit
onSubtitleData(
    controller: MediaController,
    item: MediaItem,
    track: SessionPlayer.TrackInfo,
    data: SubtitleData
)

Called when the subtitle track has new subtitle data available.

Unit
onTrackDeselected(
    controller: MediaController,
    trackInfo: SessionPlayer.TrackInfo
)

Called when a track is deselected.

Unit
onTrackSelected(
    controller: MediaController,
    trackInfo: SessionPlayer.TrackInfo
)

Called when a track is selected.

Unit
onTracksChanged(
    controller: MediaController,
    tracks: (Mutable)List<SessionPlayer.TrackInfo!>
)

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.

Unit
onVideoSizeChanged(controller: MediaController, videoSize: VideoSize)

Called when video size is changed.

Public constructors

ControllerCallback

Added in 1.0.0
Deprecated in 1.3.0
ControllerCallback()

Public functions

onAllowedCommandsChanged

Added in 1.0.0
Deprecated in 1.3.0
fun onAllowedCommandsChanged(
    controller: MediaController,
    commands: SessionCommandGroup
): Unit

Called when the allowed commands are changed by session.

Parameters
controller: MediaController

the controller for this event

commands: SessionCommandGroup

newly allowed commands

onBufferingStateChanged

Added in 1.0.0
Deprecated in 1.3.0
fun onBufferingStateChanged(
    controller: MediaController,
    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: MediaItem

the media item for which buffering is happening

state: Int

the new buffering state

onConnected

Added in 1.0.0
Deprecated in 1.3.0
fun onConnected(
    controller: MediaController,
    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: SessionCommandGroup

commands that's allowed by the session

onCurrentMediaItemChanged

Added in 1.0.0
Deprecated in 1.3.0
fun onCurrentMediaItemChanged(controller: MediaController, item: MediaItem?): Unit

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
controller: MediaController

the controller for this event

item: MediaItem?

new current media item

onCustomCommand

Added in 1.0.0
Deprecated in 1.3.0
fun onCustomCommand(
    controller: MediaController,
    command: SessionCommand,
    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, RESULT_ERROR_UNKNOWN will be returned.

Default implementation returns RESULT_ERROR_NOT_SUPPORTED.

Parameters
controller: MediaController

the controller for this event

command: SessionCommand
args: Bundle?
Returns
SessionResult

result of handling custom command

onDisconnected

Added in 1.0.0
Deprecated in 1.3.0
fun onDisconnected(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

Added in 1.0.0
Deprecated in 1.3.0
fun onPlaybackCompleted(controller: MediaController): Unit

Called when the playback is completed.

Parameters
controller: MediaController

the controller for this event

onPlaybackInfoChanged

Added in 1.0.0
Deprecated in 1.3.0
fun onPlaybackInfoChanged(
    controller: MediaController,
    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 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: MediaController

the controller for this event

info: MediaController.PlaybackInfo

new playback info

onPlaybackSpeedChanged

Added in 1.0.0
Deprecated in 1.3.0
fun onPlaybackSpeedChanged(controller: MediaController, speed: Float): Unit

Called when playback speed is changed.

Parameters
controller: MediaController

the controller for this event

speed: Float

speed

onPlayerStateChanged

Added in 1.0.0
Deprecated in 1.3.0
fun onPlayerStateChanged(controller: MediaController, state: Int): Unit

Called when the player state is changed.

Parameters
controller: MediaController

the controller for this event

state: Int

the new player state

onPlaylistChanged

Added in 1.0.0
Deprecated in 1.3.0
fun onPlaylistChanged(
    controller: MediaController,
    list: (Mutable)List<MediaItem!>?,
    metadata: MediaMetadata?
): Unit

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
controller: MediaController

the controller for this event

list: (Mutable)List<MediaItem!>?

new playlist

metadata: MediaMetadata?

new metadata

onPlaylistMetadataChanged

Added in 1.0.0
Deprecated in 1.3.0
fun onPlaylistMetadataChanged(
    controller: MediaController,
    metadata: MediaMetadata?
): Unit

Called when a playlist metadata is changed.

Parameters
controller: MediaController

the controller for this event

metadata: MediaMetadata?

new metadata

onRepeatModeChanged

Added in 1.0.0
Deprecated in 1.3.0
fun onRepeatModeChanged(controller: MediaController, repeatMode: Int): Unit

Called when the repeat mode is changed.

Parameters
controller: MediaController

the controller for this event

repeatMode: Int

repeat mode

onSeekCompleted

Added in 1.0.0
Deprecated in 1.3.0
fun onSeekCompleted(controller: MediaController, position: Long): Unit

Called to indicate that seeking is completed.

Parameters
controller: MediaController

the controller for this event

position: Long

the previous seeking request

onSetCustomLayout

Added in 1.0.0
Deprecated in 1.3.0
fun onSetCustomLayout(
    controller: MediaController,
    layout: (Mutable)List<MediaSession.CommandButton!>
): Int

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
controller: MediaController

the controller for this event

layout: (Mutable)List<MediaSession.CommandButton!>

onShuffleModeChanged

Added in 1.0.0
Deprecated in 1.3.0
fun onShuffleModeChanged(controller: MediaController, shuffleMode: Int): Unit

Called when the shuffle mode is changed.

Parameters
controller: MediaController

the controller for this event

shuffleMode: Int

repeat mode

onSubtitleData

Added in 1.1.0
Deprecated in 1.3.0
fun onSubtitleData(
    controller: MediaController,
    item: MediaItem,
    track: SessionPlayer.TrackInfo,
    data: SubtitleData
): Unit

Called when the subtitle track has new subtitle data available.

Parameters
controller: MediaController

the controller for this event

item: MediaItem

the MediaItem of this media item

track: SessionPlayer.TrackInfo

the track that has the subtitle data

data: SubtitleData

the subtitle data

onTrackDeselected

Added in 1.1.0
Deprecated in 1.3.0
fun onTrackDeselected(
    controller: MediaController,
    trackInfo: SessionPlayer.TrackInfo
): Unit

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: MediaController

the controller for this event

trackInfo: SessionPlayer.TrackInfo

the deselected track

onTrackSelected

Added in 1.1.0
Deprecated in 1.3.0
fun onTrackSelected(
    controller: MediaController,
    trackInfo: SessionPlayer.TrackInfo
): Unit

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: MediaController

the controller for this event

trackInfo: SessionPlayer.TrackInfo

the selected track

onTracksChanged

Added in 1.1.0
Deprecated in 1.3.0
fun onTracksChanged(
    controller: MediaController,
    tracks: (Mutable)List<SessionPlayer.TrackInfo!>
): Unit

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
controller: MediaController

the controller for this event

tracks: (Mutable)List<SessionPlayer.TrackInfo!>

the list of tracks. It can be empty.

onVideoSizeChanged

Added in 1.1.0
Deprecated in 1.3.0
fun onVideoSizeChanged(controller: MediaController, videoSize: VideoSize): Unit

Called when video size is changed.

Parameters
controller: MediaController

the controller for this event

videoSize: VideoSize

the size of video