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