public abstract class

MediaPlayer.PlayerCallback

extends SessionPlayer.PlayerCallback

 java.lang.Object

androidx.media2.SessionPlayer.PlayerCallback

↳androidx.media2.MediaPlayer.PlayerCallback

Overview

Interface definition for callbacks to be invoked when the player has the corresponding events.

Summary

Constructors
publicPlayerCallback()

Methods
public voidonDrmInfo(MediaPlayer mp, MediaItem item, MediaPlayer.DrmInfo drmInfo)

Called to indicate DRM info is available

public voidonError(MediaPlayer mp, MediaItem item, int what, int extra)

Called to indicate an error.

public voidonInfo(MediaPlayer mp, MediaItem item, int what, int extra)

Called to indicate an info or a warning.

public voidonMediaTimeDiscontinuity(MediaPlayer mp, MediaItem item, MediaTimestamp timestamp)

Called when a discontinuity in the normal progression of the media time is detected.

public voidonSubtitleData(MediaPlayer mp, MediaItem item, SubtitleData data)

Called when when a player subtitle track has new subtitle data available.

public voidonTimedMetaDataAvailable(MediaPlayer mp, MediaItem item, TimedMetaData data)

Called to indicate available timed metadata

public voidonVideoSizeChanged(MediaPlayer mp, MediaItem item, 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.

from SessionPlayer.PlayerCallbackonAudioAttributesChanged, onBufferingStateChanged, onCurrentMediaItemChanged, onPlaybackCompleted, onPlaybackSpeedChanged, onPlayerStateChanged, onPlaylistChanged, onPlaylistMetadataChanged, onRepeatModeChanged, onSeekCompleted, onShuffleModeChanged
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public PlayerCallback()

Methods

public void onVideoSizeChanged(MediaPlayer mp, MediaItem item, 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.

Parameters:

mp: the player associated with this callback
item: the MediaItem of this media item
size: the size of the video

public void onTimedMetaDataAvailable(MediaPlayer mp, MediaItem item, TimedMetaData data)

Called to indicate available timed metadata

This method will be called as timed metadata is extracted from the media, in the same order as it occurs in the media. The timing of this event is not controlled by the associated timestamp.

Currently only HTTP live streaming data URI's embedded with timed ID3 tags generates TimedMetaData.

Parameters:

mp: the player associated with this callback
item: the MediaItem of this media item
data: the timed metadata sample associated with this event

See also: TimedMetaData

public void onError(MediaPlayer mp, MediaItem item, int what, int extra)

Called to indicate an error.

Parameters:

mp: the MediaPlayer2 the error pertains to
item: the MediaItem of this media item
what: the type of error that has occurred.
extra: an extra code, specific to the error. Typically implementation dependent.

public void onInfo(MediaPlayer mp, MediaItem item, int what, int extra)

Called to indicate an info or a warning.

Parameters:

mp: the player the info pertains to.
item: the MediaItem of this media item
what: the type of info or warning.
extra: an extra code, specific to the info. Typically implementation dependent.

public void onMediaTimeDiscontinuity(MediaPlayer mp, MediaItem item, MediaTimestamp timestamp)

Called when a discontinuity in the normal progression of the media time is detected. The "normal progression" of media time is defined as the expected increase of the playback position when playing media, relative to the playback speed (for instance every second, media time increases by two seconds when playing at 2x).
Discontinuities are encountered in the following cases:

  • when the player is starved for data and cannot play anymore
  • when the player encounters a playback error
  • when the a seek operation starts, and when it's completed
  • when the playback speed changes
  • when the playback state changes
  • when the player is reset

Parameters:

mp: the player the media time pertains to.
item: the MediaItem of this media item
timestamp: the timestamp that correlates media time, system time and clock rate, or MediaTimestamp.TIMESTAMP_UNKNOWN in an error case.

public void onSubtitleData(MediaPlayer mp, MediaItem item, SubtitleData data)

Called when when a player subtitle track has new subtitle data available.

Parameters:

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

public void onDrmInfo(MediaPlayer mp, MediaItem item, MediaPlayer.DrmInfo drmInfo)

Called to indicate DRM info is available

Parameters:

mp: the MediaPlayer2 associated with this callback
item: the MediaItem of this media item
drmInfo: DRM info of the source including PSSH, and subset of crypto schemes supported by this device