Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

SessionPlayer.PlayerCallback

public static abstract class SessionPlayer.PlayerCallback
extends Object

java.lang.Object
   ↳ androidx.media2.common.SessionPlayer.PlayerCallback


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

Summary

Public constructors

SessionPlayer.PlayerCallback()

Public methods

void onAudioAttributesChanged(SessionPlayer player, AudioAttributesCompat attributes)

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

void onBufferingStateChanged(SessionPlayer player, MediaItem item, int buffState)

Called when a buffering events for a media item happened.

void onCurrentMediaItemChanged(SessionPlayer player, MediaItem item)

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

void onPlaybackCompleted(SessionPlayer player)

Called when the player finished playing.

void onPlaybackSpeedChanged(SessionPlayer player, float playbackSpeed)

Called when the playback speed has changed.

void onPlayerStateChanged(SessionPlayer player, int playerState)

Called when the state of the player has changed.

void onPlaylistChanged(SessionPlayer player, List<MediaItem> list, MediaMetadata metadata)

Called when a playlist is changed.

void onPlaylistMetadataChanged(SessionPlayer player, MediaMetadata metadata)

Called when a playlist metadata is changed.

void onRepeatModeChanged(SessionPlayer player, int repeatMode)

Called when the repeat mode is changed.

void onSeekCompleted(SessionPlayer player, long position)

Called when SessionPlayer.seekTo(long) is completed.

void onShuffleModeChanged(SessionPlayer player, int shuffleMode)

Called when the shuffle mode is changed.

Inherited methods

Public constructors

SessionPlayer.PlayerCallback

public SessionPlayer.PlayerCallback ()

Public methods

onAudioAttributesChanged

public void onAudioAttributesChanged (SessionPlayer player, 
                AudioAttributesCompat attributes)

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

public void onBufferingStateChanged (SessionPlayer player, 
                MediaItem item, 
                int buffState)

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

public void onCurrentMediaItemChanged (SessionPlayer player, 
                MediaItem item)

Called when the player's current media item has changed. It's also called after SessionPlayer.setPlaylist(List, MediaMetadata) or SessionPlayer.setMediaItem(MediaItem).

Parameters
player SessionPlayer: the player whose media item changed.

item MediaItem: the new current media item.

onPlaybackCompleted

public void onPlaybackCompleted (SessionPlayer player)

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

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

Parameters
player SessionPlayer: the player whose playback is completed.

onPlaybackSpeedChanged

public void onPlaybackSpeedChanged (SessionPlayer player, 
                float playbackSpeed)

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

public void onPlayerStateChanged (SessionPlayer player, 
                int playerState)

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

public void onPlaylistChanged (SessionPlayer player, 
                List<MediaItem> list, 
                MediaMetadata metadata)

Called when a playlist is changed. It's also called after SessionPlayer.setPlaylist(List, MediaMetadata) or SessionPlayer.setMediaItem(MediaItem).

Parameters
player SessionPlayer: the player that has changed the playlist and playlist metadata.

list List: new playlist

metadata MediaMetadata: new metadata

onPlaylistMetadataChanged

public void onPlaylistMetadataChanged (SessionPlayer player, 
                MediaMetadata metadata)

Called when a playlist metadata is changed.

Parameters
player SessionPlayer: the player that has changed the playlist metadata.

metadata MediaMetadata: new metadata

onRepeatModeChanged

public void onRepeatModeChanged (SessionPlayer player, 
                int repeatMode)

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

public void onSeekCompleted (SessionPlayer player, 
                long position)

Called when SessionPlayer.seekTo(long) is completed.

Parameters
player SessionPlayer: the player that has completed seeking.

position long: the previous seeking request.

onShuffleModeChanged

public void onShuffleModeChanged (SessionPlayer player, 
                int shuffleMode)

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