SessionPlayer.PlayerCallback

Added in 1.0.0
Deprecated in 1.3.0

public abstract class SessionPlayer.PlayerCallback

Known direct subclasses
MediaPlayer.PlayerCallback

This class is deprecated.

androidx.media2 is deprecated.

RemoteSessionPlayer.Callback

This class is deprecated.

androidx.media2 is deprecated.


A callback class to receive notifications for events on the session player. See registerPlayerCallback to register this callback.

Summary

Public constructors

Public methods

void

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

void
onBufferingStateChanged(
    @NonNull SessionPlayer player,
    @Nullable MediaItem item,
    int buffState
)

Called when a buffering events for a media item happened.

void

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

void

Called when the player finished playing.

void
onPlaybackSpeedChanged(
    @NonNull SessionPlayer player,
    float playbackSpeed
)

Called when the playback speed has changed.

void
onPlayerStateChanged(@NonNull SessionPlayer player, int playerState)

Called when the state of the player has changed.

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

Called when a playlist is changed.

void

Called when a playlist metadata is changed.

void
onRepeatModeChanged(@NonNull SessionPlayer player, int repeatMode)

Called when the repeat mode is changed.

void
onSeekCompleted(@NonNull SessionPlayer player, long position)

Called when seekTo is completed.

void
onShuffleModeChanged(@NonNull SessionPlayer player, int shuffleMode)

Called when the shuffle mode is changed.

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

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

void

Called when a track is deselected.

void

Called when a track is selected.

void

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.

void

Called to indicate the video size

Public constructors

PlayerCallback

Added in 1.0.0
Deprecated in 1.3.0
public PlayerCallback()

Public methods

onAudioAttributesChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onAudioAttributesChanged(
    @NonNull SessionPlayer player,
    @Nullable AudioAttributesCompat attributes
)

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

Parameters
@NonNull SessionPlayer player

the player whose audio attributes are changed

@Nullable AudioAttributesCompat attributes

the new current audio attributes

onBufferingStateChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onBufferingStateChanged(
    @NonNull SessionPlayer player,
    @Nullable MediaItem item,
    int buffState
)

Called when a buffering events for a media item happened.

Parameters
@NonNull SessionPlayer player

the player that is buffering

@Nullable MediaItem item

the media item for which buffering is happening

int buffState

the new buffering state

onCurrentMediaItemChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onCurrentMediaItemChanged(
    @NonNull SessionPlayer player,
    @Nullable MediaItem item
)

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
@NonNull SessionPlayer player

the player whose media item changed

@Nullable MediaItem item

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

onPlaybackCompleted

Added in 1.0.0
Deprecated in 1.3.0
public void onPlaybackCompleted(@NonNull SessionPlayer player)

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
@NonNull SessionPlayer player

the player whose playback is completed

See also
REPEAT_MODE_NONE

onPlaybackSpeedChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onPlaybackSpeedChanged(
    @NonNull SessionPlayer player,
    float playbackSpeed
)

Called when the playback speed has changed.

Parameters
@NonNull SessionPlayer player

the player that has changed the playback speed

float playbackSpeed

the new playback speed

See also
getPlaybackSpeed

onPlayerStateChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onPlayerStateChanged(@NonNull SessionPlayer player, int playerState)

Called when the state of the player has changed.

Parameters
@NonNull SessionPlayer player

the player whose state has changed

int playerState

the new state of the player

See also
getPlayerState

onPlaylistChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onPlaylistChanged(
    @NonNull SessionPlayer player,
    @Nullable List<MediaItem> list,
    @Nullable MediaMetadata metadata
)

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

Parameters
@NonNull SessionPlayer player

the player that has changed the playlist and playlist metadata

@Nullable List<MediaItem> list

new playlist

@Nullable MediaMetadata metadata

new metadata

onPlaylistMetadataChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onPlaylistMetadataChanged(
    @NonNull SessionPlayer player,
    @Nullable MediaMetadata metadata
)

Called when a playlist metadata is changed.

Parameters
@NonNull SessionPlayer player

the player that has changed the playlist metadata

@Nullable MediaMetadata metadata

new metadata

onRepeatModeChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onRepeatModeChanged(@NonNull SessionPlayer player, int repeatMode)

Called when the repeat mode is changed.

getPreviousMediaItemIndex and 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
@NonNull SessionPlayer player

player for this event

int repeatMode

repeat mode

onSeekCompleted

Added in 1.0.0
Deprecated in 1.3.0
public void onSeekCompleted(@NonNull SessionPlayer player, long position)

Called when seekTo is completed.

Parameters
@NonNull SessionPlayer player

the player that has completed seeking

long position

the previous seeking request

onShuffleModeChanged

Added in 1.0.0
Deprecated in 1.3.0
public void onShuffleModeChanged(@NonNull SessionPlayer player, int shuffleMode)

Called when the shuffle mode is changed.

getPreviousMediaItemIndex and 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
@NonNull SessionPlayer player

playlist agent for this event

int shuffleMode

shuffle mode

onSubtitleData

Added in 1.1.0
Deprecated in 1.3.0
public void onSubtitleData(
    @NonNull SessionPlayer player,
    @NonNull MediaItem item,
    @NonNull SessionPlayer.TrackInfo track,
    @NonNull SubtitleData data
)

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

Parameters
@NonNull SessionPlayer player

the player that reports the new subtitle data

@NonNull MediaItem item

the MediaItem of this media item

@NonNull SessionPlayer.TrackInfo track

the track that has the subtitle data

@NonNull SubtitleData data

the subtitle data

onTrackDeselected

Added in 1.1.0
Deprecated in 1.3.0
public void onTrackDeselected(
    @NonNull SessionPlayer player,
    @NonNull SessionPlayer.TrackInfo trackInfo
)

Called when a track is deselected.

This callback will generally be called only after calling deselectTrack.

Parameters
@NonNull SessionPlayer player

the player associated with this callback

@NonNull SessionPlayer.TrackInfo trackInfo

the deselected track

See also
deselectTrack

onTrackSelected

Added in 1.1.0
Deprecated in 1.3.0
public void onTrackSelected(
    @NonNull SessionPlayer player,
    @NonNull SessionPlayer.TrackInfo trackInfo
)

Called when a track is selected.

Parameters
@NonNull SessionPlayer player

the player associated with this callback

@NonNull SessionPlayer.TrackInfo trackInfo

the selected track

See also
selectTrack

onTracksChanged

Added in 1.1.0
Deprecated in 1.3.0
public void onTracksChanged(
    @NonNull SessionPlayer player,
    @NonNull 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 selectTrack or deselectTrack.

Parameters
@NonNull SessionPlayer player

the player associated with this callback

@NonNull List<SessionPlayer.TrackInfo> tracks

the list of tracks. It can be empty

See also
getTracks

onVideoSizeChanged

Added in 1.1.0
Deprecated in 1.3.0
public void onVideoSizeChanged(@NonNull SessionPlayer player, @NonNull 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 onCurrentMediaItemChanged is called.

Parameters
@NonNull SessionPlayer player

the player associated with this callback

@NonNull VideoSize size

the size of the video

See also
getVideoSize