MediaPlayer

class MediaPlayer : SessionPlayer
kotlin.Any
   ↳ androidx.media2.common.SessionPlayer
   ↳ androidx.media2.player.MediaPlayer

A media player which plays MediaItems. The details on playback control and player states can be found in the documentation of the base class, SessionPlayer.

Topic covered here:

  1. Audio focus and noisy intent

Audio focus and noisy intent

By default, MediaPlayer handles audio focus and noisy intent with AudioAttributesCompat set to this player. You need to call setAudioAttributes(AudioAttributesCompat) set the audio attribute while in the PLAYER_STATE_IDLE.

Here's the table of automatic audio focus behavior with audio attributes.

Audio Attributes Audio Focus Gain Type Misc
AudioAttributesCompat#USAGE_VOICE_COMMUNICATION_SIGNALLING android.media.AudioManager#AUDIOFOCUS_NONE
android.media.AudioManager#AUDIOFOCUS_GAIN Developers should specific a proper usage instead of AudioAttributesCompat#USAGE_UNKNOWN
android.media.AudioManager#AUDIOFOCUS_GAIN_TRANSIENT
android.media.AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
android.media.AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
AudioAttributesCompat#USAGE_ASSISTANCE_ACCESSIBILITY android.media.AudioManager#AUDIOFOCUS_GAIN_TRANSIENT if AudioAttributesCompat#CONTENT_TYPE_SPEECH, android.media.AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK otherwise
null No audio focus handling, and sets the player volume to 0 Only valid if your media contents don't have audio
Any other AudioAttributes No audio focus handling, and sets the player volume to 0 This is to handle error

If an AudioAttributesCompat is not specified by setAudioAttributes, getAudioAttributes will return null and the default audio focus behavior will follow the null case on the table above.

For more information about the audio focus, take a look at Managing audio focus

Summary

Nested classes

abstract

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

Class for the player to return each audio/video/subtitle track's metadata.

Constants

static Int

Informs that audio is not playing.

static Int

Bad interleaving means that a media has been improperly interleaved or not interleaved at all, e.

static Int

Update status in buffering a media source received through progressive downloading.

static Int

A new set of metadata is available.

static Int

The media cannot be seeked (e.g live stream)

static Int

Informs that video is not playing.

static Int

The player just pushed the very first video frame for rendering.

static Int

The video is too complex for the decoder: it can't decode frames fast enough.

static Int

The return value of getSelectedTrack when there is no selected track for the given type.

static Int

File or network related operation errors.

static Int

Bitstream is not conforming to the related coding standard or file spec.

static Int

Some operation takes too long to complete, usually more than 3-5 seconds.

static Int

Unspecified player error.

static Int

Bitstream is conforming to the related coding standard or file spec, but the media framework does not support the feature.

static Int

This mode is used with seekTo(long, int) to move media position to a frame (not necessarily a key frame) associated with a media item that is located closest to or at the given time.

static Int

This mode is used with seekTo(long, int) to move media position to a sync (or key) frame associated with a media item that is located closest to (in time) or at the given time.

static Int

This mode is used with seekTo(long, int) to move media position to a sync (or key) frame associated with a media item that is located right after or at the given time.

static Int

This mode is used with seekTo(long, int) to move media position to a sync (or key) frame associated with a media item that is located right before or at the given time.

Inherited constants

Public constructors

<init>(@NonNull context: Context)

Constructor to create a MediaPlayer instance.

Public methods

ListenableFuture<SessionPlayer.PlayerResult!>
addPlaylistItem(index: Int, @NonNull item: MediaItem)

ListenableFuture<SessionPlayer.PlayerResult!>
attachAuxEffect(effectId: Int)

Attaches an auxiliary effect to the player.

Unit

AudioAttributesCompat?

Int

Returns the audio session ID.

Long

Int

MediaItem?

Int

Long

Long

Float

Int

PlaybackParams

Gets the playback params, containing the current playback rate.

Float

Int

Float

MutableList<MediaItem!>?

MediaMetadata?

Int

Int

MediaPlayer.TrackInfo?
getSelectedTrack(trackType: Int)

Returns the audio or video track currently selected for playback.

Int

MediaTimestamp?

Gets current playback position as a MediaTimestamp.

MutableList<MediaPlayer.TrackInfo!>

Returns a List of track information.

VideoSize

Returns the size of the video.

ListenableFuture<SessionPlayer.PlayerResult!>

ListenableFuture<SessionPlayer.PlayerResult!>

ListenableFuture<SessionPlayer.PlayerResult!>

Prepares the media items for playback.

Unit
registerPlayerCallback(@NonNull executor: Executor, @NonNull callback: MediaPlayer.PlayerCallback)

Register PlayerCallback to listen changes.

ListenableFuture<SessionPlayer.PlayerResult!>

ListenableFuture<SessionPlayer.PlayerResult!>
replacePlaylistItem(index: Int, @NonNull item: MediaItem)

Unit

Resets MediaPlayer to its uninitialized state if not closed.

ListenableFuture<SessionPlayer.PlayerResult!>
seekTo(position: Long)

ListenableFuture<SessionPlayer.PlayerResult!>
seekTo(position: Long, mode: Int)

Moves the media to specified time position by considering the given mode.

ListenableFuture<SessionPlayer.PlayerResult!>
selectTrack(@NonNull trackInfo: MediaPlayer.TrackInfo)

Selects a track.

ListenableFuture<SessionPlayer.PlayerResult!>

ListenableFuture<SessionPlayer.PlayerResult!>
setAudioSessionId(sessionId: Int)

Sets the audio session ID.

ListenableFuture<SessionPlayer.PlayerResult!>

Sets the send level of the player to the attached auxiliary effect.

ListenableFuture<SessionPlayer.PlayerResult!>
setMediaItem(@NonNull item: MediaItem)

ListenableFuture<SessionPlayer.PlayerResult!>

Sets playback params using PlaybackParams.

ListenableFuture<SessionPlayer.PlayerResult!>
setPlaybackSpeed(playbackSpeed: Float)

Sets the playback speed.

ListenableFuture<SessionPlayer.PlayerResult!>

Sets the volume of the audio of the media to play, expressed as a linear multiplier on the audio samples.

ListenableFuture<SessionPlayer.PlayerResult!>
setPlaylist(@NonNull playlist: MutableList<MediaItem!>, @Nullable metadata: MediaMetadata?)

ListenableFuture<SessionPlayer.PlayerResult!>
setRepeatMode(repeatMode: Int)

ListenableFuture<SessionPlayer.PlayerResult!>
setShuffleMode(shuffleMode: Int)

ListenableFuture<SessionPlayer.PlayerResult!>
setSurface(@Nullable surface: Surface?)

Sets the Surface to be used as the sink for the video portion of the media.

ListenableFuture<SessionPlayer.PlayerResult!>

ListenableFuture<SessionPlayer.PlayerResult!>

ListenableFuture<SessionPlayer.PlayerResult!>

Unit

Unregister the previously registered PlayerCallback.

ListenableFuture<SessionPlayer.PlayerResult!>
updatePlaylistMetadata(@Nullable metadata: MediaMetadata?)

Inherited functions

Constants

MEDIA_INFO_AUDIO_NOT_PLAYING

static val MEDIA_INFO_AUDIO_NOT_PLAYING: Int

Informs that audio is not playing. Note that playback of the video is not interrupted.

Value: 804

MEDIA_INFO_BAD_INTERLEAVING

static val MEDIA_INFO_BAD_INTERLEAVING: Int

Bad interleaving means that a media has been improperly interleaved or not interleaved at all, e.g has all the video samples first then all the audio ones. Video is playing but a lot of disk seeks may be happening.

Value: 800

MEDIA_INFO_BUFFERING_UPDATE

static val MEDIA_INFO_BUFFERING_UPDATE: Int

Update status in buffering a media source received through progressive downloading. The received buffering percentage indicates how much of the content has been buffered or played. For example a buffering update of 80 percent when half the content has already been played indicates that the next 30 percent of the content to play has been buffered.

The extra parameter in PlayerCallback#onInfo is the percentage (0-100) of the content that has been buffered or played thus far.

Value: 704

MEDIA_INFO_METADATA_UPDATE

static val MEDIA_INFO_METADATA_UPDATE: Int

A new set of metadata is available.

Value: 802

MEDIA_INFO_NOT_SEEKABLE

static val MEDIA_INFO_NOT_SEEKABLE: Int

The media cannot be seeked (e.g live stream)

Value: 801

MEDIA_INFO_VIDEO_NOT_PLAYING

static val MEDIA_INFO_VIDEO_NOT_PLAYING: Int

Informs that video is not playing. Note that playback of the audio is not interrupted.

Value: 805

MEDIA_INFO_VIDEO_RENDERING_START

static val MEDIA_INFO_VIDEO_RENDERING_START: Int

The player just pushed the very first video frame for rendering.

Value: 3

MEDIA_INFO_VIDEO_TRACK_LAGGING

static val MEDIA_INFO_VIDEO_TRACK_LAGGING: Int

The video is too complex for the decoder: it can't decode frames fast enough. Possibly only the audio plays fine at this stage.

Value: 700

NO_TRACK_SELECTED

static val NO_TRACK_SELECTED: Int

The return value of getSelectedTrack when there is no selected track for the given type.

Value: Integer.MIN_VALUE

PLAYER_ERROR_IO

static val PLAYER_ERROR_IO: Int

File or network related operation errors.

Value: -1004

PLAYER_ERROR_MALFORMED

static val PLAYER_ERROR_MALFORMED: Int

Bitstream is not conforming to the related coding standard or file spec.

Value: -1007

PLAYER_ERROR_TIMED_OUT

static val PLAYER_ERROR_TIMED_OUT: Int

Some operation takes too long to complete, usually more than 3-5 seconds.

Value: -110

PLAYER_ERROR_UNKNOWN

static val PLAYER_ERROR_UNKNOWN: Int

Unspecified player error.

Value: 1

PLAYER_ERROR_UNSUPPORTED

static val PLAYER_ERROR_UNSUPPORTED: Int

Bitstream is conforming to the related coding standard or file spec, but the media framework does not support the feature.

Value: -1010

SEEK_CLOSEST

static val SEEK_CLOSEST: Int

This mode is used with seekTo(long, int) to move media position to a frame (not necessarily a key frame) associated with a media item that is located closest to or at the given time.

Value: 0x03

SEEK_CLOSEST_SYNC

static val SEEK_CLOSEST_SYNC: Int

This mode is used with seekTo(long, int) to move media position to a sync (or key) frame associated with a media item that is located closest to (in time) or at the given time.

Value: 0x02

SEEK_NEXT_SYNC

static val SEEK_NEXT_SYNC: Int

This mode is used with seekTo(long, int) to move media position to a sync (or key) frame associated with a media item that is located right after or at the given time.

Value: 0x01

SEEK_PREVIOUS_SYNC

static val SEEK_PREVIOUS_SYNC: Int

This mode is used with seekTo(long, int) to move media position to a sync (or key) frame associated with a media item that is located right before or at the given time.

Value: 0x00

Public constructors

<init>

MediaPlayer(@NonNull context: Context)

Constructor to create a MediaPlayer instance.

Parameters
context Context: A Context that will be used to resolve UriMediaItem.

Public methods

addPlaylistItem

@NonNull fun addPlaylistItem(index: Int, @NonNull item: MediaItem): ListenableFuture<SessionPlayer.PlayerResult!>

attachAuxEffect

@NonNull fun attachAuxEffect(effectId: Int): ListenableFuture<SessionPlayer.PlayerResult!>

Attaches an auxiliary effect to the player. A typical auxiliary effect is a reverberation effect which can be applied on any sound source that directs a certain amount of its energy to this effect. This amount is defined by setAuxEffectSendLevel(). See setAuxEffectSendLevel(float).

After creating an auxiliary effect (e.g. android.media.audiofx.EnvironmentalReverb), retrieve its ID with android.media.audiofx.AudioEffect#getId() and use it when calling this method to attach the player to the effect.

To detach the effect from the player, call this method with a null effect id.

This method must be called before setMediaItem and setPlaylist methods.

Parameters
effectId Int: system wide unique id of the effect to attach
Return
ListenableFuture<SessionPlayer.PlayerResult!>: a ListenableFuture which represents the pending completion of the command. SessionPlayer.PlayerResult will be delivered when the command completed.

On success, a SessionPlayer.PlayerResult is returned with the current media item when the command completed.

close

fun close(): Unit

getAudioAttributes

@Nullable fun getAudioAttributes(): AudioAttributesCompat?

getAudioSessionId

fun getAudioSessionId(): Int

Returns the audio session ID.

Return
Int: the audio session ID. {@see #setAudioSessionId(int)} Note that the audio session ID is 0 if a problem occurred when the MediaPlayer was constructed or it is closed.

getBufferedPosition

fun getBufferedPosition(): Long

getBufferingState

fun getBufferingState(): Int

getCurrentMediaItem

@Nullable fun getCurrentMediaItem(): MediaItem?

getCurrentMediaItemIndex

fun getCurrentMediaItemIndex(): Int

getCurrentPosition

fun getCurrentPosition(): Long

getDuration

fun getDuration(): Long

getMaxPlayerVolume

fun getMaxPlayerVolume(): Float
Return
Float: the maximum volume that can be used in setPlayerVolume(float).

getNextMediaItemIndex

fun getNextMediaItemIndex(): Int

getPlaybackParams

@NonNull fun getPlaybackParams(): PlaybackParams

Gets the playback params, containing the current playback rate.

Return
PlaybackParams: the playback params.

getPlaybackSpeed

fun getPlaybackSpeed(): Float

getPlayerState

fun getPlayerState(): Int

getPlayerVolume

fun getPlayerVolume(): Float
Return
Float: the current volume of this player to this player. Note that it does not take into account the associated stream volume.

getPlaylist

@Nullable fun getPlaylist(): MutableList<MediaItem!>?

getPlaylistMetadata

@Nullable fun getPlaylistMetadata(): MediaMetadata?

getPreviousMediaItemIndex

fun getPreviousMediaItemIndex(): Int

getRepeatMode

fun getRepeatMode(): Int

getSelectedTrack

@Nullable fun getSelectedTrack(trackType: Int): MediaPlayer.TrackInfo?

Returns the audio or video track currently selected for playback. The return value is an element in the list returned by getTrackInfo(), and can be used in calls to selectTrack(TrackInfo).

Parameters
trackType Int: should be one of TrackInfo#MEDIA_TRACK_TYPE_VIDEO or TrackInfo#MEDIA_TRACK_TYPE_AUDIO
Return
MediaPlayer.TrackInfo?: metadata corresponding to the audio or video track currently selected for playback; null is returned when there is no selected track for trackType or when trackType is not one of audio or video.
Exceptions
IllegalStateException if called after close()

getShuffleMode

fun getShuffleMode(): Int

getTimestamp

@Nullable fun getTimestamp(): MediaTimestamp?

Gets current playback position as a MediaTimestamp.

The MediaTimestamp represents how the media time correlates to the system time in a linear fashion using an anchor and a clock rate. During regular playback, the media time moves fairly constantly (though the anchor frame may be rebased to a current system time, the linear correlation stays steady). Therefore, this method does not need to be called often.

To help users get current playback position, this method always anchors the timestamp to the current system time, so MediaTimestamp#getAnchorMediaTimeUs can be used as current playback position.

Return
MediaTimestamp?: a MediaTimestamp object if a timestamp is available, or null if no timestamp is available, e.g. because the media player has not been initialized.

See Also

getTrackInfo

@NonNull fun getTrackInfo(): MutableList<MediaPlayer.TrackInfo!>

Returns a List of track information.

Return
MutableList<MediaPlayer.TrackInfo!>: List of track info. The total number of tracks is the size of the list.

getVideoSize

@NonNull fun getVideoSize(): VideoSize

Returns the size of the video.

Return
VideoSize: the size of the video. The width and height of size could be 0 if there is no video or the size has not been determined yet. The PlayerCallback can be registered via registerPlayerCallback to receive a notification PlayerCallback#onVideoSizeChanged when the size is available.

pause

@NonNull fun pause(): ListenableFuture<SessionPlayer.PlayerResult!>

play

@NonNull fun play(): ListenableFuture<SessionPlayer.PlayerResult!>

prepare

@NonNull fun prepare(): ListenableFuture<SessionPlayer.PlayerResult!>

Prepares the media items for playback.

After setting the media items and the display surface, you need to call this method. During this preparation, the player may allocate resources required to play, such as audio and video decoders.

On success, a SessionPlayer.PlayerResult is returned with the current media item when the command completed.

Return
ListenableFuture<SessionPlayer.PlayerResult!>: a ListenableFuture which represents the pending completion of the command. SessionPlayer.PlayerResult will be delivered when the command completed.

registerPlayerCallback

fun registerPlayerCallback(@NonNull executor: Executor, @NonNull callback: MediaPlayer.PlayerCallback): Unit

Register PlayerCallback to listen changes.

Parameters
executor Executor: a callback Executor
callback Executor: a PlayerCallback
Exceptions
IllegalArgumentException if executor or callback is null.

removePlaylistItem

@NonNull fun removePlaylistItem(index: Int): ListenableFuture<SessionPlayer.PlayerResult!>

replacePlaylistItem

@NonNull fun replacePlaylistItem(index: Int, @NonNull item: MediaItem): ListenableFuture<SessionPlayer.PlayerResult!>

reset

fun reset(): Unit

Resets MediaPlayer to its uninitialized state if not closed. After calling this method, you will have to initialize it again by setting the media item and calling prepare().

Note that if the player is closed, there is no way to reuse the instance.

seekTo

@NonNull fun seekTo(position: Long): ListenableFuture<SessionPlayer.PlayerResult!>

seekTo

@NonNull fun seekTo(position: Long, mode: Int): ListenableFuture<SessionPlayer.PlayerResult!>

Moves the media to specified time position by considering the given mode.

There is at most one active seekTo processed at any time. If there is a to-be-completed seekTo, new seekTo requests will be queued in such a way that only the last request is kept. When current seekTo is completed, the queued request will be processed if that request is different from just-finished seekTo operation, i.e., the requested position or mode is different.

On success, a SessionPlayer.PlayerResult is returned with the current media item when the command completed.

Parameters
position Long: the offset in milliseconds from the start to seek to. When seeking to the given time position, there is no guarantee that the media item has a frame located at the position. When this happens, a frame nearby will be rendered. The value should be in the range of start and end positions defined in MediaItem.
mode Long: the mode indicating where exactly to seek to.
Return
ListenableFuture<SessionPlayer.PlayerResult!>: a ListenableFuture which represents the pending completion of the command. SessionPlayer.PlayerResult will be delivered when the command completed.

selectTrack

@NonNull fun selectTrack(@NonNull trackInfo: MediaPlayer.TrackInfo): ListenableFuture<SessionPlayer.PlayerResult!>

Selects a track.

If the player is in invalid state, SessionPlayer.PlayerResult#RESULT_ERROR_INVALID_STATE will be reported with SessionPlayer.PlayerResult. If a player is in Playing state, the selected track is presented immediately. If a player is not in Playing state, it just marks the track to be played.

In any valid state, if it is called multiple times on the same type of track (ie. Video, Audio), the most recent one will be chosen.

The first audio and video tracks are selected by default if available, even though this method is not called.

Currently, audio tracks can be selected via this method.

Parameters
trackInfo MediaPlayer.TrackInfo: metadata corresponding to the track to be selected. A trackInfo object can be obtained from getTrackInfo().

On success, a SessionPlayer.PlayerResult is returned with the current media item when the command completed.

Return
ListenableFuture<SessionPlayer.PlayerResult!>: a ListenableFuture which represents the pending completion of the command. SessionPlayer.PlayerResult will be delivered when the command completed.

See Also

setAudioAttributes

@NonNull fun setAudioAttributes(@NonNull attr: AudioAttributesCompat): ListenableFuture<SessionPlayer.PlayerResult!>

setAudioSessionId

@NonNull fun setAudioSessionId(sessionId: Int): ListenableFuture<SessionPlayer.PlayerResult!>

Sets the audio session ID.

Parameters
sessionId Int: the audio session ID. The audio session ID is a system wide unique identifier for the audio stream played by this MediaPlayer2 instance. The primary use of the audio session ID is to associate audio effects to a particular instance of MediaPlayer2: if an audio session ID is provided when creating an audio effect, this effect will be applied only to the audio content of media players within the same audio session and not to the output mix. When created, a MediaPlayer2 instance automatically generates its own audio session ID. However, it is possible to force this player to be part of an already existing audio session by calling this method.

This method must be called before setMediaItem and setPlaylist methods.

Return
ListenableFuture<SessionPlayer.PlayerResult!>: a ListenableFuture which represents the pending completion of the command. SessionPlayer.PlayerResult will be delivered when the command completed.

On success, a SessionPlayer.PlayerResult is returned with the current media item when the command completed.

setAuxEffectSendLevel

@NonNull fun setAuxEffectSendLevel(level: Float): ListenableFuture<SessionPlayer.PlayerResult!>

Sets the send level of the player to the attached auxiliary effect. See attachAuxEffect(int). The level value range is 0 to 1.0.

By default the send level is 0, so even if an effect is attached to the player this method must be called for the effect to be applied.

Note that the passed level value is a raw scalar. UI controls should be scaled logarithmically: the gain applied by audio framework ranges from -72dB to 0dB, so an appropriate conversion from linear UI input x to level is: x == 0 -> level = 0 0 < x <= R -> level = 10^(72*(x-R)/20/R)

On success, a SessionPlayer.PlayerResult is returned with the current media item when the command completed.

Parameters
level Float: send level scalar
Return
ListenableFuture<SessionPlayer.PlayerResult!>: a ListenableFuture which represents the pending completion of the command. SessionPlayer.PlayerResult will be delivered when the command completed.

setMediaItem

@NonNull fun setMediaItem(@NonNull item: MediaItem): ListenableFuture<SessionPlayer.PlayerResult!>

setPlaybackParams

@NonNull fun setPlaybackParams(@NonNull params: PlaybackParams): ListenableFuture<SessionPlayer.PlayerResult!>

Sets playback params using PlaybackParams.

On success, a SessionPlayer.PlayerResult is returned with the current media item when the command completed.

Parameters
params PlaybackParams: the playback params.
Return
ListenableFuture<SessionPlayer.PlayerResult!>: a ListenableFuture which represents the pending completion of the command. SessionPlayer.PlayerResult will be delivered when the command completed.

setPlaybackSpeed

@NonNull fun setPlaybackSpeed(playbackSpeed: Float): ListenableFuture<SessionPlayer.PlayerResult!>

Sets the playback speed. 1.0f is the default, and values less than or equal to 0.0f are not allowed.

The supported playback speed range depends on the underlying player implementation, so it is recommended to query the actual speed of the player via getPlaybackSpeed() after the operation completes.

Parameters
playbackSpeed Float: The requested playback speed.
Return
ListenableFuture<SessionPlayer.PlayerResult!>: A ListenableFuture representing the pending completion of the command.

setPlayerVolume

@NonNull fun setPlayerVolume(volume: Float): ListenableFuture<SessionPlayer.PlayerResult!>

Sets the volume of the audio of the media to play, expressed as a linear multiplier on the audio samples.

Note that this volume is specific to the player, and is separate from stream volume used across the platform.

A value of 0.0f indicates muting, a value of 1.0f is the nominal unattenuated and unamplified gain. See getMaxPlayerVolume() for the volume range supported by this player.

The default player volume is 1.0f.

On success, a SessionPlayer.PlayerResult is returned with the current media item when the command completed.

Parameters
volume Float: a value between 0.0f and getMaxPlayerVolume().
Return
ListenableFuture<SessionPlayer.PlayerResult!>: a ListenableFuture which represents the pending completion of the command. SessionPlayer.PlayerResult will be delivered when the command completed.

setPlaylist

@NonNull fun setPlaylist(@NonNull playlist: MutableList<MediaItem!>, @Nullable metadata: MediaMetadata?): ListenableFuture<SessionPlayer.PlayerResult!>

setRepeatMode

@NonNull fun setRepeatMode(repeatMode: Int): ListenableFuture<SessionPlayer.PlayerResult!>

setShuffleMode

@NonNull fun setShuffleMode(shuffleMode: Int): ListenableFuture<SessionPlayer.PlayerResult!>

setSurface

@NonNull fun setSurface(@Nullable surface: Surface?): ListenableFuture<SessionPlayer.PlayerResult!>

Sets the Surface to be used as the sink for the video portion of the media.

A null surface will result in only the audio track being played.

If the Surface sends frames to a SurfaceTexture, the timestamps returned from SurfaceTexture#getTimestamp() will have an unspecified zero point. These timestamps cannot be directly compared between different media sources, different instances of the same media source, or multiple runs of the same program. The timestamp is normally monotonically increasing and is unaffected by time-of-day adjustments, but it is reset when the position is set.

On success, a SessionPlayer.PlayerResult is returned with the current media item when the command completed.

Parameters
surface Surface?: The Surface to be used for the video portion of the media.
Return
ListenableFuture<SessionPlayer.PlayerResult!>: a ListenableFuture which represents the pending completion of the command. SessionPlayer.PlayerResult will be delivered when the command completed.

skipToNextPlaylistItem

@NonNull fun skipToNextPlaylistItem(): ListenableFuture<SessionPlayer.PlayerResult!>

skipToPlaylistItem

@NonNull fun skipToPlaylistItem(index: Int): ListenableFuture<SessionPlayer.PlayerResult!>

skipToPreviousPlaylistItem

@NonNull fun skipToPreviousPlaylistItem(): ListenableFuture<SessionPlayer.PlayerResult!>

unregisterPlayerCallback

fun unregisterPlayerCallback(@NonNull callback: MediaPlayer.PlayerCallback): Unit

Unregister the previously registered PlayerCallback.

Parameters
callback MediaPlayer.PlayerCallback: the callback to be removed
Exceptions
IllegalArgumentException if the callback is null.

updatePlaylistMetadata

@NonNull fun updatePlaylistMetadata(@Nullable metadata: MediaMetadata?): ListenableFuture<SessionPlayer.PlayerResult!>