MediaPlayer.PlayerCallback

Added in 1.0.0
Deprecated in 1.3.0

public abstract class MediaPlayer.PlayerCallback extends SessionPlayer.PlayerCallback


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

Summary

Public constructors

Public methods

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

Called to indicate an error.

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

Called to indicate an info or a warning.

void
onMediaTimeDiscontinuity(
    @NonNull MediaPlayer mp,
    @NonNull MediaItem item,
    @NonNull MediaTimestamp timestamp
)

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

void

Called to indicate available timed metadata

void

Called to indicate the video size

void
onVideoSizeChanged(
    @NonNull MediaPlayer mp,
    @NonNull MediaItem item,
    @NonNull VideoSize size
)

This method is deprecated.

Use onVideoSizeChanged instead.

Inherited methods

From androidx.media2.common.SessionPlayer.PlayerCallback
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.

Public constructors

PlayerCallback

Added in 1.0.0
Deprecated in 1.3.0
public PlayerCallback()

Public methods

onError

Added in 1.0.0
Deprecated in 1.3.0
public void onError(
    @NonNull MediaPlayer mp,
    @NonNull MediaItem item,
    int what,
    int extra
)

Called to indicate an error.

Parameters
@NonNull MediaPlayer mp

the MediaPlayer2 the error pertains to

@NonNull MediaItem item

the MediaItem of this media item

int what

the type of error that has occurred.

int extra

an extra code, specific to the error. Typically implementation dependent.

onInfo

Added in 1.0.0
Deprecated in 1.3.0
public void onInfo(@NonNull MediaPlayer mp, @NonNull MediaItem item, int what, int extra)

Called to indicate an info or a warning.

Parameters
@NonNull MediaPlayer mp

the player the info pertains to.

@NonNull MediaItem item

the MediaItem of this media item

int what

the type of info or warning.

int extra

an extra code, specific to the info. Typically implementation dependent.

onMediaTimeDiscontinuity

Added in 1.0.0
Deprecated in 1.3.0
public void onMediaTimeDiscontinuity(
    @NonNull MediaPlayer mp,
    @NonNull MediaItem item,
    @NonNull 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
@NonNull MediaPlayer mp

the player the media time pertains to.

@NonNull MediaItem item

the MediaItem of this media item

@NonNull MediaTimestamp timestamp

the timestamp that correlates media time, system time and clock rate, or TIMESTAMP_UNKNOWN in an error case.

onTimedMetaDataAvailable

Added in 1.0.0
Deprecated in 1.3.0
public void onTimedMetaDataAvailable(
    @NonNull MediaPlayer mp,
    @NonNull MediaItem item,
    @NonNull 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
@NonNull MediaPlayer mp

the player associated with this callback

@NonNull MediaItem item

the MediaItem of this media item

@NonNull TimedMetaData data

the timed metadata sample associated with this event

See also
TimedMetaData

onVideoSizeChanged

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.

Parameters
@NonNull SessionPlayer player

the player associated with this callback

@NonNull VideoSize size

the size of the video

onVideoSizeChanged

Added in 1.0.0
Deprecated in 1.1.0
public void onVideoSizeChanged(
    @NonNull MediaPlayer mp,
    @NonNull MediaItem item,
    @NonNull VideoSize size
)