MediaPlayer.PlayerCallback

Added in 1.0.0
Deprecated in 1.3.0

abstract class MediaPlayer.PlayerCallback : SessionPlayer.PlayerCallback


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

Summary

Public constructors

Public functions

Unit
onError(mp: MediaPlayer, item: MediaItem, what: Int, extra: Int)

Called to indicate an error.

Unit
onInfo(mp: MediaPlayer, item: MediaItem, what: Int, extra: Int)

Called to indicate an info or a warning.

Unit
onMediaTimeDiscontinuity(
    mp: MediaPlayer,
    item: MediaItem,
    timestamp: MediaTimestamp
)

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

Unit
onTimedMetaDataAvailable(
    mp: MediaPlayer,
    item: MediaItem,
    data: TimedMetaData
)

Called to indicate available timed metadata

Unit

Called to indicate the video size

Unit

This function is deprecated.

Use onVideoSizeChanged instead.

Inherited functions

From androidx.media2.common.SessionPlayer.PlayerCallback
Unit
onAudioAttributesChanged(
    player: SessionPlayer,
    attributes: AudioAttributesCompat?
)

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

Unit
onBufferingStateChanged(
    player: SessionPlayer,
    item: MediaItem?,
    buffState: Int
)

Called when a buffering events for a media item happened.

Unit

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

Unit

Called when the player finished playing.

Unit
onPlaybackSpeedChanged(player: SessionPlayer, playbackSpeed: Float)

Called when the playback speed has changed.

Unit
onPlayerStateChanged(player: SessionPlayer, playerState: Int)

Called when the state of the player has changed.

Unit
onPlaylistChanged(
    player: SessionPlayer,
    list: (Mutable)List<MediaItem!>?,
    metadata: MediaMetadata?
)

Called when a playlist is changed.

Unit

Called when a playlist metadata is changed.

Unit
onRepeatModeChanged(player: SessionPlayer, repeatMode: Int)

Called when the repeat mode is changed.

Unit
onSeekCompleted(player: SessionPlayer, position: Long)

Called when seekTo is completed.

Unit
onShuffleModeChanged(player: SessionPlayer, shuffleMode: Int)

Called when the shuffle mode is changed.

Unit
onSubtitleData(
    player: SessionPlayer,
    item: MediaItem,
    track: SessionPlayer.TrackInfo,
    data: SubtitleData
)

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

Unit
onTrackDeselected(
    player: SessionPlayer,
    trackInfo: SessionPlayer.TrackInfo
)

Called when a track is deselected.

Unit
onTrackSelected(
    player: SessionPlayer,
    trackInfo: SessionPlayer.TrackInfo
)

Called when a track is selected.

Unit
onTracksChanged(
    player: SessionPlayer,
    tracks: (Mutable)List<SessionPlayer.TrackInfo!>
)

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
PlayerCallback()

Public functions

onError

Added in 1.0.0
Deprecated in 1.3.0
fun onError(mp: MediaPlayer, item: MediaItem, what: Int, extra: Int): Unit

Called to indicate an error.

Parameters
mp: MediaPlayer

the MediaPlayer2 the error pertains to

item: MediaItem

the MediaItem of this media item

what: Int

the type of error that has occurred.

extra: Int

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

onInfo

Added in 1.0.0
Deprecated in 1.3.0
fun onInfo(mp: MediaPlayer, item: MediaItem, what: Int, extra: Int): Unit

Called to indicate an info or a warning.

Parameters
mp: MediaPlayer

the player the info pertains to.

item: MediaItem

the MediaItem of this media item

what: Int

the type of info or warning.

extra: Int

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

onMediaTimeDiscontinuity

Added in 1.0.0
Deprecated in 1.3.0
fun onMediaTimeDiscontinuity(
    mp: MediaPlayer,
    item: MediaItem,
    timestamp: MediaTimestamp
): Unit

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: MediaPlayer

the player the media time pertains to.

item: MediaItem

the MediaItem of this media item

timestamp: MediaTimestamp

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
fun onTimedMetaDataAvailable(
    mp: MediaPlayer,
    item: MediaItem,
    data: TimedMetaData
): Unit

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: MediaPlayer

the player associated with this callback

item: MediaItem

the MediaItem of this media item

data: TimedMetaData

the timed metadata sample associated with this event

See also
TimedMetaData

onVideoSizeChanged

fun onVideoSizeChanged(player: SessionPlayer, size: VideoSize): Unit

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
player: SessionPlayer

the player associated with this callback

size: VideoSize

the size of the video

onVideoSizeChanged

Added in 1.0.0
Deprecated in 1.1.0
fun onVideoSizeChanged(mp: MediaPlayer, item: MediaItem, size: VideoSize): Unit