PlayerAdapter

abstract class PlayerAdapter
kotlin.Any
   ↳ androidx.leanback.media.PlayerAdapter

Base class that wraps underlying media player. The class is used by PlaybackGlue, for example PlaybackTransportControlGlue is bound to a PlayerAdapter. This class is intended to be subclassed, MediaPlayerAdapter is a concrete subclass using android.media.MediaPlayer.

Summary

Nested classes
open

Client for client of PlayerAdapter.

Public constructors

Public methods
open Boolean

Returns true if media is currently playing.

open Long

Return xor combination of values defined in PlaybackBaseControlGlue.

open Long

Returns the duration of the media item in milliseconds.

abstract Unit

Pauses the media player.

open Unit

Optional method.

open Unit
seekTo(positionInMs: Long)

Seek to new position.

open Boolean

open Long

Returns the current position of the media item in milliseconds.

open Unit

Optional method.

open Unit

Implement this method to enable or disable progress updating.

open Unit

This method is called attached to associated PlaybackGlueHost.

Unit

Sets callback for event of PlayerAdapter.

PlayerAdapter.Callback!

Gets callback for event of PlayerAdapter.

abstract Unit

Starts the media player.

open Unit

Optional method.

open Unit

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

open Unit
setRepeatAction(repeatActionIndex: Int)

Optional method.

open Unit
setShuffleAction(shuffleActionIndex: Int)

Optional method.

open Long

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

open Unit

Optional method.

Public constructors

<init>

PlayerAdapter()

Public methods

isPlaying

open fun isPlaying(): Boolean

Returns true if media is currently playing.

getSupportedActions

open fun getSupportedActions(): Long

Return xor combination of values defined in PlaybackBaseControlGlue. Default is PLAY_PAUSE (unless subclass enforce to be 0)

getDuration

open fun getDuration(): Long

Returns the duration of the media item in milliseconds.

pause

abstract fun pause(): Unit

Pauses the media player.

previous

open fun previous(): Unit

Optional method. Override this method if #getSupportedActions() include PlaybackBaseControlGlue#ACTION_SKIP_TO_PREVIOUS to skip to previous item.

seekTo

open fun seekTo(positionInMs: Long): Unit

Seek to new position.

Parameters
positionInMs Long: New position in milliseconds.

isPrepared

open fun isPrepared(): Boolean
Return
Boolean: True if media is ready for playback, false otherwise.

getCurrentPosition

open fun getCurrentPosition(): Long

Returns the current position of the media item in milliseconds.

fastForward

open fun fastForward(): Unit

Optional method. Override this method if #getSupportedActions() include PlaybackBaseControlGlue#ACTION_FAST_FORWARD to fast forward current media item.

setProgressUpdatingEnabled

open fun setProgressUpdatingEnabled(enable: Boolean): Unit

Implement this method to enable or disable progress updating.

Parameters
enable Boolean: True to enable progress updating, false otherwise.

onAttachedToHost

open fun onAttachedToHost(host: PlaybackGlueHost!): Unit

This method is called attached to associated PlaybackGlueHost.

Parameters
host PlaybackGlueHost!:

setCallback

fun setCallback(callback: PlayerAdapter.Callback!): Unit

Sets callback for event of PlayerAdapter.

Parameters
callback PlayerAdapter.Callback!: Client for event of PlayerAdapter.

getCallback

fun getCallback(): PlayerAdapter.Callback!

Gets callback for event of PlayerAdapter.

Return
PlayerAdapter.Callback!: Client for event of PlayerAdapter.

play

abstract fun play(): Unit

Starts the media player.

next

open fun next(): Unit

Optional method. Override this method if #getSupportedActions() include PlaybackBaseControlGlue#ACTION_SKIP_TO_NEXT to skip to next item.

onDetachedFromHost

open 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.

setRepeatAction

open fun setRepeatAction(repeatActionIndex: Int): Unit

Optional method. Override this method if #getSupportedActions() include PlaybackBaseControlGlue#ACTION_REPEAT to set the repeat action.

Parameters
repeatActionIndex Int: The shuffle action. Must be one of the followings: androidx.leanback.widget.PlaybackControlsRow.RepeatAction#INDEX_ONE androidx.leanback.widget.PlaybackControlsRow.RepeatAction#INDEX_ALL, androidx.leanback.widget.PlaybackControlsRow.RepeatAction#INDEX_NONE,

setShuffleAction

open fun setShuffleAction(shuffleActionIndex: Int): Unit

Optional method. Override this method if #getSupportedActions() include PlaybackBaseControlGlue#ACTION_SHUFFLE to set the shuffle action.

Parameters
shuffleActionIndex Int: The repeat action. Must be one of the followings: androidx.leanback.widget.PlaybackControlsRow.ShuffleAction#INDEX_OFF androidx.leanback.widget.PlaybackControlsRow.ShuffleAction#INDEX_ON

getBufferedPosition

open fun getBufferedPosition(): Long

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

rewind

open fun rewind(): Unit

Optional method. Override this method if #getSupportedActions() include PlaybackBaseControlGlue#ACTION_REWIND to rewind in current media item.