public abstract class

SessionPlayer.PlayerCallback

extends java.lang.Object

 java.lang.Object

↳androidx.media2.common.SessionPlayer.PlayerCallback

Subclasses:

RemoteSessionPlayer.Callback, MediaPlayer.PlayerCallback

Overview

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

Summary

Constructors
publicPlayerCallback()

Methods
public voidonAudioAttributesChanged(SessionPlayer player, AudioAttributesCompat attributes)

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

public voidonBufferingStateChanged(SessionPlayer player, MediaItem item, int buffState)

Called when a buffering events for a media item happened.

public voidonCurrentMediaItemChanged(SessionPlayer player, MediaItem item)

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

public voidonPlaybackCompleted(SessionPlayer player)

Called when the player finished playing.

public voidonPlaybackSpeedChanged(SessionPlayer player, float playbackSpeed)

Called when the playback speed has changed.

public voidonPlayerStateChanged(SessionPlayer player, int playerState)

Called when the state of the player has changed.

public voidonPlaylistChanged(SessionPlayer player, java.util.List<MediaItem> list, MediaMetadata metadata)

Called when a playlist is changed.

public voidonPlaylistMetadataChanged(SessionPlayer player, MediaMetadata metadata)

Called when a playlist metadata is changed.

public voidonRepeatModeChanged(SessionPlayer player, int repeatMode)

Called when the repeat mode is changed.

public voidonSeekCompleted(SessionPlayer player, long position)

Called when SessionPlayer.seekTo(long) is completed.

public voidonShuffleModeChanged(SessionPlayer player, int shuffleMode)

Called when the shuffle mode is changed.

public voidonSubtitleData(SessionPlayer player, MediaItem item, SessionPlayer.TrackInfo track, SubtitleData data)

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

public voidonTrackDeselected(SessionPlayer player, SessionPlayer.TrackInfo trackInfo)

Called when a track is deselected.

public voidonTracksChanged(SessionPlayer player, java.util.List<SessionPlayer.TrackInfo> tracks)

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.

public voidonTrackSelected(SessionPlayer player, SessionPlayer.TrackInfo trackInfo)

Called when a track is selected.

public voidonVideoSizeChanged(SessionPlayer player, VideoSize size)

Called to indicate the video size

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public PlayerCallback()

Methods

public void onPlayerStateChanged(SessionPlayer player, int playerState)

Called when the state of the player has changed.

Parameters:

player: the player whose state has changed
playerState: the new state of the player

See also: SessionPlayer.getPlayerState()

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

Called when a buffering events for a media item happened.

Parameters:

player: the player that is buffering
item: the media item for which buffering is happening
buffState: the new buffering state

See also: SessionPlayer.getBufferingState()

public void onPlaybackSpeedChanged(SessionPlayer player, float playbackSpeed)

Called when the playback speed has changed.

Parameters:

player: the player that has changed the playback speed
playbackSpeed: the new playback speed

See also: SessionPlayer.getPlaybackSpeed()

public void onSeekCompleted(SessionPlayer player, long position)

Called when SessionPlayer.seekTo(long) is completed.

Parameters:

player: the player that has completed seeking
position: the previous seeking request

See also: SessionPlayer.getCurrentPosition()

public void onPlaylistChanged(SessionPlayer player, java.util.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: the player that has changed the playlist and playlist metadata
list: new playlist
metadata: new metadata

See also: SessionPlayer.getPlaylist(), SessionPlayer.getPlaylistMetadata()

public void onPlaylistMetadataChanged(SessionPlayer player, MediaMetadata metadata)

Called when a playlist metadata is changed.

Parameters:

player: the player that has changed the playlist metadata
metadata: new metadata

See also: SessionPlayer.getPlaylistMetadata()

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: playlist agent for this event
shuffleMode: shuffle mode

See also: SessionPlayer.SHUFFLE_MODE_NONE, SessionPlayer.SHUFFLE_MODE_ALL, SessionPlayer.SHUFFLE_MODE_GROUP, SessionPlayer.getShuffleMode()

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: player for this event
repeatMode: repeat mode

See also: SessionPlayer.REPEAT_MODE_NONE, SessionPlayer.REPEAT_MODE_ONE, SessionPlayer.REPEAT_MODE_ALL, SessionPlayer.REPEAT_MODE_GROUP, SessionPlayer.getRepeatMode()

public void onCurrentMediaItemChanged(SessionPlayer player, MediaItem item)

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

Parameters:

player: the player whose media item changed
item: the new current media item. This can be null when the state of the player becomes SessionPlayer.PLAYER_STATE_IDLE.

See also: SessionPlayer.getCurrentMediaItem()

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: the player whose playback is completed

See also: SessionPlayer.REPEAT_MODE_NONE

public void onAudioAttributesChanged(SessionPlayer player, AudioAttributesCompat attributes)

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

Parameters:

player: the player whose audio attributes are changed
attributes: the new current audio attributes

See also: SessionPlayer.getAudioAttributes()

public void onVideoSizeChanged(SessionPlayer player, VideoSize size)

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 SessionPlayer.PlayerCallback.onCurrentMediaItemChanged(SessionPlayer, MediaItem) is called.

Parameters:

player: the player associated with this callback
size: the size of the video

See also: SessionPlayer.getVideoSize()

public void onSubtitleData(SessionPlayer player, MediaItem item, SessionPlayer.TrackInfo track, SubtitleData data)

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

Parameters:

player: the player that reports the new subtitle data
item: the MediaItem of this media item
track: the track that has the subtitle data
data: the subtitle data

public void onTracksChanged(SessionPlayer player, java.util.List<SessionPlayer.TrackInfo> tracks)

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 SessionPlayer.selectTrack(SessionPlayer.TrackInfo) or SessionPlayer.deselectTrack(SessionPlayer.TrackInfo).

Parameters:

player: the player associated with this callback
tracks: the list of tracks. It can be empty

See also: SessionPlayer.getTracks()

public void onTrackSelected(SessionPlayer player, SessionPlayer.TrackInfo trackInfo)

Called when a track is selected.

Parameters:

player: the player associated with this callback
trackInfo: the selected track

See also: SessionPlayer.selectTrack(SessionPlayer.TrackInfo)

public void onTrackDeselected(SessionPlayer player, SessionPlayer.TrackInfo trackInfo)

Called when a track is deselected.

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

Parameters:

player: the player associated with this callback
trackInfo: the deselected track

See also: SessionPlayer.deselectTrack(SessionPlayer.TrackInfo)