Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

MediaPlayerAdapter

open class MediaPlayerAdapter : PlayerAdapter
kotlin.Any
   ↳ androidx.leanback.media.PlayerAdapter
   ↳ androidx.leanback.media.MediaPlayerAdapter

This implementation extends the PlayerAdapter with a MediaPlayer.

Summary

Public constructors

<init>(context: Context!)

Constructor.

Public methods

open Long

open Long

open Long

MediaPlayer!

Return the MediaPlayer associated with the MediaPlayerAdapter.

open Int

Return updating interval of progress UI in milliseconds.

open Boolean

open Boolean

open Unit

open Unit

open Unit

open Unit

open Unit

Release internal MediaPlayer.

open Unit

Will reset the MediaPlayer and the glue such that a new file can be played.

open Unit
seekTo(newPosition: Long)

open Boolean

Sets the media source of the player witha given URI.

open Unit

Protected methods

open Boolean
onError(what: Int, extra: Int)

Called to indicate an error.

open Boolean
onInfo(what: Int, extra: Int)

Called to indicate an info or a warning.

open Unit

Called to indicate the completion of a seek operation.

Inherited functions

Public constructors

<init>

MediaPlayerAdapter(context: Context!)

Constructor.

Public methods

getBufferedPosition

open fun getBufferedPosition(): Long

getCurrentPosition

open fun getCurrentPosition(): Long

getDuration

open fun getDuration(): Long

getMediaPlayer

fun getMediaPlayer(): MediaPlayer!

Return the MediaPlayer associated with the MediaPlayerAdapter. App can use the instance to config DRM or control volumes, etc. Warning: App should not use the following seven listeners as they are controlled by MediaPlayerAdapter. If that's the case, app should write its own PlayerAdapter class. MediaPlayer#setOnPreparedListener MediaPlayer#setOnVideoSizeChangedListener MediaPlayer#setOnErrorListener MediaPlayer#setOnSeekCompleteListener MediaPlayer#setOnCompletionListener MediaPlayer#setOnInfoListener MediaPlayer#setOnBufferingUpdateListener

Return
MediaPlayer!: The MediaPlayer associated with the MediaPlayerAdapter.

getProgressUpdatingInterval

open fun getProgressUpdatingInterval(): Int

Return updating interval of progress UI in milliseconds. Subclass may override.

Return
Int: Update interval of progress UI in milliseconds.

isPlaying

open fun isPlaying(): Boolean

isPrepared

open fun isPrepared(): Boolean
Return
Boolean: True if MediaPlayer OnPreparedListener is invoked and got a SurfaceHolder if PlaybackGlueHost provides SurfaceHolder.

onAttachedToHost

open fun onAttachedToHost(host: PlaybackGlueHost!): Unit

onDetachedFromHost

open fun onDetachedFromHost(): Unit

pause

open fun pause(): Unit

play

open fun play(): Unit

release

open fun release(): Unit

Release internal MediaPlayer. Should not use the object after call release().

reset

open fun reset(): Unit

Will reset the MediaPlayer and the glue such that a new file can be played. You are not required to call this method before playing the first file. However you have to call it before playing a second one.

seekTo

open fun seekTo(newPosition: Long): Unit

setDataSource

open fun setDataSource(uri: Uri!): Boolean

Sets the media source of the player witha given URI.

Return
Boolean: Returns true if uri represents a new media; false otherwise.

setProgressUpdatingEnabled

open fun setProgressUpdatingEnabled(enabled: Boolean): Unit

Protected methods

onError

protected open fun onError(what: Int, extra: Int): Boolean

Called to indicate an error.

Parameters
what Int: the type of error that has occurred:
extra Int: an extra code, specific to the error. Typically implementation dependent.
Return
Boolean: True if the method handled the error, false if it didn't. Returning false, will cause the PlayerAdapter.Callback#onPlayCompleted(PlayerAdapter) being called.

onInfo

protected open fun onInfo(what: Int, extra: Int): Boolean

Called to indicate an info or a warning.

Parameters
what Int: the type of info or warning.
extra Int: an extra code, specific to the info. Typically implementation dependent.
Return
Boolean: True if the method handled the info, false if it didn't. Returning false, will cause the info to be discarded.

onSeekComplete

protected open fun onSeekComplete(): Unit

Called to indicate the completion of a seek operation.