The Android Developer Challenge is back! Submit your idea before December 2.

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.

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 SessionPlayer: 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 SessionPlayer: the media item for which buffering is happening.
buffState SessionPlayer: 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. It's also called after setPlaylist or setMediaItem.

Parameters
player SessionPlayer: the player whose media item changed.
item SessionPlayer: 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 SessionPlayer: 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 SessionPlayer: 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 SessionPlayer: new playlist
metadata SessionPlayer: 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 SessionPlayer: 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 SessionPlayer: 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 SessionPlayer: 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 SessionPlayer: shuffle mode