MediaPlayerAdapter

class MediaPlayerAdapter : PlayerAdapter


This implementation extends the PlayerAdapter with a MediaPlayer.

Summary

Public constructors

Constructor.

Public functions

Long

Returns the current buffered position of the media item in milliseconds.

Long

Returns the current position of the media item in milliseconds.

Long

Returns the duration of the media item in milliseconds.

MediaPlayer!

Return the MediaPlayer associated with the MediaPlayerAdapter.

Int

Return updating interval of progress UI in milliseconds.

Boolean

Returns true if media is currently playing.

Boolean
Unit

This method is called attached to associated PlaybackGlueHost.

Unit

This method is called when current associated PlaybackGlueHost is attached to a different PlaybackGlue or PlaybackGlueHost is destroyed.

Unit

Pauses the media player.

Unit

Starts the media player.

Unit

Release internal MediaPlayer.

Unit

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

Unit
seekTo(positionInMs: Long)

Seek to new position.

Boolean

Sets the media source of the player witha given URI.

Unit

Implement this method to enable or disable progress updating.

Protected functions

Boolean
onError(what: Int, extra: Int)

Called to indicate an error.

Boolean
onInfo(what: Int, extra: Int)

Called to indicate an info or a warning.

Unit

Called to indicate the completion of a seek operation.

Inherited functions

From androidx.leanback.media.PlayerAdapter
Unit

Optional method.

PlayerAdapter.Callback?

Gets callback for event of PlayerAdapter.

Long

Return xor combination of values defined in PlaybackBaseControlGlue.

Unit

Optional method.

Unit

Optional method.

Unit

Optional method.

Unit

Sets callback for event of PlayerAdapter.

Unit
setRepeatAction(repeatActionIndex: Int)

Optional method.

Unit
setShuffleAction(shuffleActionIndex: Int)

Optional method.

Public constructors

MediaPlayerAdapter

Added in 1.1.0
MediaPlayerAdapter(context: Context!)

Constructor.

Public functions

getBufferedPosition

fun getBufferedPosition(): Long

Returns the current buffered position of the media item in milliseconds.

getCurrentPosition

fun getCurrentPosition(): Long

Returns the current position of the media item in milliseconds.

getDuration

fun getDuration(): Long

Returns the duration of the media item in milliseconds.

getMediaPlayer

Added in 1.1.0
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. setOnPreparedListenersetOnVideoSizeChangedListenersetOnErrorListenersetOnSeekCompleteListenersetOnCompletionListenersetOnInfoListenersetOnBufferingUpdateListener

Returns
MediaPlayer!

The MediaPlayer associated with the MediaPlayerAdapter.

getProgressUpdatingInterval

Added in 1.1.0
fun getProgressUpdatingInterval(): Int

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

Returns
Int

Update interval of progress UI in milliseconds.

isPlaying

fun isPlaying(): Boolean

Returns true if media is currently playing.

isPrepared

fun isPrepared(): Boolean
Returns
Boolean

True if MediaPlayer OnPreparedListener is invoked and got a SurfaceHolder if PlaybackGlueHost provides SurfaceHolder.

onAttachedToHost

fun onAttachedToHost(host: PlaybackGlueHost): Unit

This method is called attached to associated PlaybackGlueHost.

Parameters
host: PlaybackGlueHost

onDetachedFromHost

fun onDetachedFromHost(): Unit

This method is called when current associated PlaybackGlueHost is attached to a different PlaybackGlue or PlaybackGlueHost is destroyed. Subclass may override. A typical implementation will release resources (e.g. MediaPlayer or connection to playback service) in this method.

pause

Added in 1.2.0-alpha04
fun pause(): Unit

Pauses the media player.

play

Added in 1.2.0-alpha04
fun play(): Unit

Starts the media player.

release

Added in 1.1.0
fun release(): Unit

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

reset

Added in 1.1.0
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

fun seekTo(positionInMs: Long): Unit

Seek to new position.

Parameters
positionInMs: Long

New position in milliseconds.

setDataSource

Added in 1.1.0
fun setDataSource(uri: Uri!): Boolean

Sets the media source of the player witha given URI.

Returns
Boolean

Returns true if uri represents a new media; falseotherwise.

See also
setDataSource

setProgressUpdatingEnabled

fun setProgressUpdatingEnabled(enable: Boolean): Unit

Implement this method to enable or disable progress updating.

Parameters
enable: Boolean

True to enable progress updating, false otherwise.

Protected functions

onError

Added in 1.1.0
protected 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.

Returns
Boolean

True if the method handled the error, false if it didn't. Returning false, will cause the onPlayCompleted being called.

onInfo

Added in 1.1.0
protected 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.

Returns
Boolean

True if the method handled the info, false if it didn't. Returning false, will cause the info to be discarded.

onSeekComplete

Added in 1.1.0
protected fun onSeekComplete(): Unit

Called to indicate the completion of a seek operation.