Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

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

Return the MediaPlayer associated with the MediaPlayerAdapter.

open Long

open Unit
seekTo(newPosition: Long)

open Long

open Unit

open Unit

open Boolean

Sets the media source of the player witha given URI.

open Unit

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

open Boolean

open Unit

open Boolean

open Unit

open Unit

open Int

Return updating interval of progress UI in milliseconds.

open Long

open Unit

Release internal MediaPlayer.

Protected methods
open Unit

Called to indicate the completion of a seek operation.

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

Called to indicate an info or a warning.

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

Called to indicate an error.

Inherited functions

Public constructors

<init>

MediaPlayerAdapter(context: Context!)

Constructor.

Public methods

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.

getDuration

open fun getDuration(): Long

seekTo

open fun seekTo(newPosition: Long): Unit

getCurrentPosition

open fun getCurrentPosition(): Long

setProgressUpdatingEnabled

open fun setProgressUpdatingEnabled(enabled: Boolean): Unit

play

open fun play(): 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.

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.

isPlaying

open fun isPlaying(): Boolean

pause

open fun pause(): Unit

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

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.

getBufferedPosition

open fun getBufferedPosition(): Long

release

open fun release(): Unit

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

Protected methods

onSeekComplete

protected open fun onSeekComplete(): Unit

Called to indicate the completion of a seek operation.

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.

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.