PlayerAdapter


abstract class PlayerAdapter

Known direct subclasses
LeanbackPlayerAdapter

Leanback PlayerAdapter implementation for Player.

MediaControllerAdapter

A helper class for implementing a adapter layer for MediaControllerCompat.

MediaPlayerAdapter

This implementation extends the PlayerAdapter with a MediaPlayer.


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. ExoPlayer also provides a leanback extension that implements PlayerAdapter. Please see ExoPlayer https://developer.android.com/guide/topics/media/exoplayer

Summary

Nested types

Client for client of PlayerAdapter.

Public constructors

Public functions

Unit

Optional method.

Long

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

PlayerAdapter.Callback?

Gets callback for event of PlayerAdapter.

Long

Returns the current position of the media item in milliseconds.

Long

Returns the duration of the media item in milliseconds.

Long

Return xor combination of values defined in PlaybackBaseControlGlue.

Boolean

Returns true if media is currently playing.

Boolean
Unit

Optional method.

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.

abstract Unit

Pauses the media player.

abstract Unit

Starts the media player.

Unit

Optional method.

Unit

Optional method.

Unit
seekTo(positionInMs: Long)

Seek to new position.

Unit

Sets callback for event of PlayerAdapter.

Unit

Implement this method to enable or disable progress updating.

Unit
setRepeatAction(repeatActionIndex: Int)

Optional method.

Unit
setShuffleAction(shuffleActionIndex: Int)

Optional method.

Public constructors

PlayerAdapter

Added in 1.1.0
PlayerAdapter()

Public functions

fastForward

Added in 1.1.0
fun fastForward(): Unit

Optional method. Override this method if getSupportedActions include ACTION_FAST_FORWARD to fast forward current media item.

getBufferedPosition

Added in 1.1.0
fun getBufferedPosition(): Long

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

getCallback

Added in 1.1.0
fun getCallback(): PlayerAdapter.Callback?

Gets callback for event of PlayerAdapter.

Returns
PlayerAdapter.Callback?

Client for event of PlayerAdapter.

getCurrentPosition

Added in 1.1.0
fun getCurrentPosition(): Long

Returns the current position of the media item in milliseconds.

getDuration

Added in 1.1.0
fun getDuration(): Long

Returns the duration of the media item in milliseconds.

getSupportedActions

Added in 1.1.0
fun getSupportedActions(): Long

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

isPlaying

Added in 1.1.0
fun isPlaying(): Boolean

Returns true if media is currently playing.

isPrepared

Added in 1.1.0
fun isPrepared(): Boolean
Returns
Boolean

True if media is ready for playback, false otherwise.

next

Added in 1.1.0
fun next(): Unit

Optional method. Override this method if getSupportedActions include ACTION_SKIP_TO_NEXT to skip to next item.

onAttachedToHost

Added in 1.1.0
fun onAttachedToHost(host: PlaybackGlueHost): Unit

This method is called attached to associated PlaybackGlueHost.

Parameters
host: PlaybackGlueHost

onDetachedFromHost

Added in 1.1.0
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.1.0
abstract fun pause(): Unit

Pauses the media player.

play

Added in 1.1.0
abstract fun play(): Unit

Starts the media player.

previous

Added in 1.1.0
fun previous(): Unit

Optional method. Override this method if getSupportedActions include ACTION_SKIP_TO_PREVIOUS to skip to previous item.

rewind

Added in 1.1.0
fun rewind(): Unit

Optional method. Override this method if getSupportedActions include ACTION_REWIND to rewind in current media item.

seekTo

Added in 1.1.0
fun seekTo(positionInMs: Long): Unit

Seek to new position.

Parameters
positionInMs: Long

New position in milliseconds.

setCallback

Added in 1.1.0
fun setCallback(callback: PlayerAdapter.Callback?): Unit

Sets callback for event of PlayerAdapter.

Parameters
callback: PlayerAdapter.Callback?

Client for event of PlayerAdapter.

setProgressUpdatingEnabled

Added in 1.1.0
fun setProgressUpdatingEnabled(enable: Boolean): Unit

Implement this method to enable or disable progress updating.

Parameters
enable: Boolean

True to enable progress updating, false otherwise.

setRepeatAction

Added in 1.1.0
fun setRepeatAction(repeatActionIndex: Int): Unit

Optional method. Override this method if getSupportedActions include ACTION_REPEAT to set the repeat action.

Parameters
repeatActionIndex: Int

The shuffle action. Must be one of the followings: INDEX_ONEINDEX_ALL, INDEX_NONE,

setShuffleAction

Added in 1.1.0
fun setShuffleAction(shuffleActionIndex: Int): Unit

Optional method. Override this method if getSupportedActions include ACTION_SHUFFLE to set the shuffle action.

Parameters
shuffleActionIndex: Int

The repeat action. Must be one of the followings: INDEX_OFFINDEX_ON