Google is committed to advancing racial equity for Black communities. See how.

PlayerCallback

abstract class PlayerCallback
kotlin.Any
   ↳ androidx.media2.common.SessionPlayer.PlayerCallback

A callback class to receive notifications for events on the session player. See registerPlayerCallback(Executor, PlayerCallback) to register this callback.

Summary

Public constructors

A callback class to receive notifications for events on the session player.

Public methods
open Unit
onAudioAttributesChanged(@NonNull player: SessionPlayer, @Nullable attributes: AudioAttributesCompat?)

Called when the player's current audio attributes are changed.

open Unit
onBufferingStateChanged(@NonNull player: SessionPlayer, @Nullable item: MediaItem?, buffState: Int)

Called when a buffering events for a media item happened.

open Unit
onCurrentMediaItemChanged(@NonNull player: SessionPlayer, @NonNull item: MediaItem)

Called when the player's current media item has changed.

open Unit

Called when the player finished playing.

open Unit
onPlaybackSpeedChanged(@NonNull player: SessionPlayer, playbackSpeed: Float)

Called when the playback speed has changed.

open Unit
onPlayerStateChanged(@NonNull player: SessionPlayer, playerState: Int)

Called when the state of the player has changed.

open Unit
onPlaylistChanged(@NonNull player: SessionPlayer, @Nullable list: MutableList<MediaItem!>?, @Nullable metadata: MediaMetadata?)

Called when a playlist is changed.

open Unit
onPlaylistMetadataChanged(@NonNull player: SessionPlayer, @Nullable metadata: MediaMetadata?)

Called when a playlist metadata is changed.

open Unit
onRepeatModeChanged(@NonNull player: SessionPlayer, repeatMode: Int)

Called when the repeat mode is changed.

open Unit
onSeekCompleted(@NonNull player: SessionPlayer, position: Long)

Called when seekTo(long) is completed.

open Unit
onShuffleModeChanged(@NonNull player: SessionPlayer, shuffleMode: Int)

Called when the shuffle mode is changed.

open Unit
onSubtitleData(@NonNull player: SessionPlayer, @NonNull item: MediaItem, @NonNull track: SessionPlayer.TrackInfo, @NonNull data: SubtitleData)

Called when the player's subtitle track has new subtitle data available.

open Unit
onTrackDeselected(@NonNull player: SessionPlayer, @NonNull trackInfo: SessionPlayer.TrackInfo)

Called when a track is deselected.

open Unit
onTrackSelected(@NonNull player: SessionPlayer, @NonNull trackInfo: SessionPlayer.TrackInfo)

Called when a track is selected.

open Unit
onTracksChanged(@NonNull player: SessionPlayer, @NonNull tracks: MutableList<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.

open Unit
onVideoSizeChanged(@NonNull player: SessionPlayer, @NonNull size: VideoSize)

Called to indicate the video size

Public constructors

<init>

PlayerCallback()

A callback class to receive notifications for events on the session player. See registerPlayerCallback(Executor, PlayerCallback) to register this callback.

Public methods

onAudioAttributesChanged

open fun onAudioAttributesChanged(
    @NonNull player: SessionPlayer,
    @Nullable attributes: AudioAttributesCompat?
): Unit

Called when the player's current audio attributes are changed.

Parameters
player SessionPlayer: the player whose audio attributes are changed
attributes AudioAttributesCompat?: the new current audio attributes

onBufferingStateChanged

open fun onBufferingStateChanged(
    @NonNull player: SessionPlayer,
    @Nullable item: MediaItem?,
    buffState: Int
): Unit

Called when a buffering events for a media item happened.

Parameters
player SessionPlayer: the player that is buffering
item MediaItem?: the media item for which buffering is happening
buffState Int: the new buffering state

onCurrentMediaItemChanged

open fun onCurrentMediaItemChanged(
    @NonNull player: SessionPlayer,
    @NonNull item: MediaItem
): Unit

Called when the player's current media item has changed. Generally called after a new media item is set through setPlaylist or setMediaItem, or after skipping to a different item in a given playlist.

Parameters
player SessionPlayer: the player whose media item changed
item MediaItem: the new current media item

onPlaybackCompleted

open fun onPlaybackCompleted(@NonNull player: SessionPlayer): Unit

Called when the player finished playing. Playback state would be also set PLAYER_STATE_PAUSED with it.

This will be called only when the repeat mode is set to REPEAT_MODE_NONE.

Parameters
player SessionPlayer: the player whose playback is completed

onPlaybackSpeedChanged

open fun onPlaybackSpeedChanged(
    @NonNull player: SessionPlayer,
    playbackSpeed: Float
): Unit

Called when the playback speed has changed.

Parameters
player SessionPlayer: the player that has changed the playback speed
playbackSpeed Float: the new playback speed

onPlayerStateChanged

open fun onPlayerStateChanged(
    @NonNull player: SessionPlayer,
    playerState: Int
): Unit

Called when the state of the player has changed.

Parameters
player SessionPlayer: the player whose state has changed
playerState Int: the new state of the player

onPlaylistChanged

open fun onPlaylistChanged(
    @NonNull player: SessionPlayer,
    @Nullable list: MutableList<MediaItem!>?,
    @Nullable metadata: MediaMetadata?
): Unit

Called when a playlist is changed. It's also called after setPlaylist or setMediaItem.

Parameters
player SessionPlayer: the player that has changed the playlist and playlist metadata
list MutableList<MediaItem!>?: new playlist
metadata MediaMetadata?: new metadata

onPlaylistMetadataChanged

open fun onPlaylistMetadataChanged(
    @NonNull player: SessionPlayer,
    @Nullable metadata: MediaMetadata?
): Unit

Called when a playlist metadata is changed.

Parameters
player SessionPlayer: the player that has changed the playlist metadata
metadata MediaMetadata?: new metadata

onRepeatModeChanged

open fun onRepeatModeChanged(
    @NonNull player: SessionPlayer,
    repeatMode: Int
): Unit

Called when the repeat mode is changed.

SessionPlayer#getPreviousMediaItemIndex() and SessionPlayer#getNextMediaItemIndex() values can be outdated when this callback is called if the current media item is the first or last item in the playlist.

Parameters
player SessionPlayer: player for this event
repeatMode Int: repeat mode

onSeekCompleted

open fun onSeekCompleted(
    @NonNull player: SessionPlayer,
    position: Long
): Unit

Called when seekTo(long) is completed.

Parameters
player SessionPlayer: the player that has completed seeking
position Long: the previous seeking request

onShuffleModeChanged

open fun onShuffleModeChanged(
    @NonNull player: SessionPlayer,
    shuffleMode: Int
): Unit

Called when the shuffle mode is changed.

SessionPlayer#getPreviousMediaItemIndex() and SessionPlayer#getNextMediaItemIndex() values can be outdated when this callback is called if the current media item is the first or last item in the playlist.

Parameters
player SessionPlayer: playlist agent for this event
shuffleMode Int: shuffle mode

onSubtitleData

open fun onSubtitleData(
    @NonNull player: SessionPlayer,
    @NonNull item: MediaItem,
    @NonNull track: SessionPlayer.TrackInfo,
    @NonNull data: SubtitleData
): Unit

Called when the player's subtitle track has new subtitle data available.

Parameters
player SessionPlayer: the player that reports the new subtitle data
item MediaItem: the MediaItem of this media item
track SessionPlayer.TrackInfo: the track that has the subtitle data
data SubtitleData: the subtitle data

onTrackDeselected

open fun onTrackDeselected(
    @NonNull player: SessionPlayer,
    @NonNull trackInfo: SessionPlayer.TrackInfo
): Unit

Called when a track is deselected.

This callback will generally be called only after calling deselectTrack(TrackInfo).

Parameters
player SessionPlayer: the player associated with this callback
trackInfo SessionPlayer.TrackInfo: the deselected track

onTrackSelected

open fun onTrackSelected(
    @NonNull player: SessionPlayer,
    @NonNull trackInfo: SessionPlayer.TrackInfo
): Unit

Called when a track is selected.

Parameters
player SessionPlayer: the player associated with this callback
trackInfo SessionPlayer.TrackInfo: the selected track

onTracksChanged

open fun onTracksChanged(
    @NonNull player: SessionPlayer,
    @NonNull tracks: MutableList<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(TrackInfo) or deselectTrack(TrackInfo).

Parameters
player SessionPlayer: the player associated with this callback
tracks MutableList<SessionPlayer.TrackInfo!>: the list of tracks. It can be empty

See Also

onVideoSizeChanged

open fun onVideoSizeChanged(
    @NonNull player: SessionPlayer,
    @NonNull size: VideoSize
): Unit

Called to indicate the video size

The video size (width and height) could be 0 if there was no video, no display surface was set, or the value was not determined yet.

This callback is generally called when player updates video size, but will also be called when PlayerCallback#onCurrentMediaItemChanged(SessionPlayer, MediaItem) is called.

Parameters
player SessionPlayer: the player associated with this callback
size VideoSize: the size of the video

See Also