PlaybackBaseControlGlue


abstract class PlaybackBaseControlGlue<T : PlayerAdapter?> : PlaybackGlue, OnActionClickedListener, View.OnKeyListener

Known direct subclasses
PlaybackBannerControlGlue

A helper class for managing a PlaybackControlsRow being displayed in PlaybackGlueHost.

PlaybackTransportControlGlue

A helper class for managing a PlaybackControlsRow being displayed in PlaybackGlueHost, it supports standard playback control actions play/pause, and skip next/previous.


A base abstract class for managing a PlaybackControlsRow being displayed in PlaybackGlueHost. It supports standard playback control actions play/pause and skip next/previous. This helper class is a glue layer that manages interaction between the leanback UI components PlaybackControlsRowPlaybackRowPresenter and a functional PlayerAdapter which represents the underlying media player.

The app must pass a PlayerAdapter in constructor for a specific implementation e.g. a MediaPlayerAdapter.

The glue has two action bars: primary action bars and secondary action bars. Apps can provide additional actions by overriding onCreatePrimaryActions and / or onCreateSecondaryActions and respond to actions by overriding onActionClicked.

The subclass is responsible for implementing the "repeat mode" in onPlayCompleted.

Parameters
<T : PlayerAdapter?>

Type of PlayerAdapter passed in constructor.

Summary

Constants

const Int

The adapter key for the first custom control on the left side of the predefined primary controls.

const Int

The adapter key for the first custom control on the right side of the predefined primary controls.

const Int

The adapter key for the fast forward control.

const Int

The adapter key for the play/pause control.

const Int

The adapter key for the repeat control.

const Int

The adapter key for the rewind control.

const Int

The adapter key for the shuffle control.

const Int

The adapter key for the skip to next control.

const Int

The adapter key for the skip to previous control.

Public constructors

PlaybackBaseControlGlue(context: Context, impl: T!)

Constructor for the glue.

Public functions

Drawable?
Long
PlaybackControlsRow?

Returns the playback controls row managed by the glue layer.

Long
Long
PlaybackRowPresenter?

Returns the playback controls row Presenter managed by the glue layer.

T!
CharSequence?

Return The media subtitle.

Long

Returns a bitmask of actions supported by the media player.

CharSequence?

Returns the title of the media item.

Boolean

Returns true if the controls auto hides after a timeout when media is playing.

Boolean

Returns true if media is currently playing.

Boolean

Returns true when the media player is prepared to start media playback.

Unit

Goes to the next media item.

abstract Unit

Handles action clicks.

abstract Boolean
onKey(v: View!, keyCode: Int, event: KeyEvent!)

Handles key events and returns true if handled.

Unit

Pauses the media player.

Unit

Starts the media player.

Unit

Goes to the previous media item.

Unit
seekTo(position: Long)

Seek media to a new position.

Unit
setArt(cover: Drawable?)

Sets the drawable representing cover image.

Unit

Sets the controls to auto hide after a timeout when media is playing.

Unit

Sets the controls row to be managed by the glue layer.

Unit

Sets the controls row Presenter to be managed by the glue layer.

Unit

Sets the media subtitle.

Unit

Sets the media title.

Protected functions

java-static Unit
Unit

This method is called attached to associated PlaybackGlueHost.

Unit

May be overridden to add primary actions to the adapter.

abstract PlaybackRowPresenter
Unit
onCreateSecondaryActions(secondaryActionsAdapter: ArrayObjectAdapter)

May be overridden to add secondary actions to the adapter.

Unit

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

Unit

This method is called when PlaybackGlueHost is started.

Unit

This method is called when PlaybackGlueHost is stopped.

Unit

Event when metadata changed

Unit

Event when play finishes, subclass may handling repeat mode here.

Unit

Event when play state changed.

Unit

Event when ready state for play changes.

Unit
Unit
Unit

Inherited functions

From androidx.leanback.media.PlaybackGlue
Unit

Add a PlayerCallback.

Context

Returns the context.

PlaybackGlueHost?
(Mutable)List<PlaybackGlue.PlayerCallback!>?
Unit

This method is called when PlaybackGlueHost is paused.

Unit

This method is called when PlaybackGlueHost is resumed.

Unit

Starts play when isPrepared becomes true.

Unit

Remove a PlayerCallback.

Unit

This method is used to associate a PlaybackGlue with the PlaybackGlueHost which provides UI and optional SurfaceHolderGlueHost.

Constants

ACTION_CUSTOM_LEFT_FIRST

Added in 1.1.0
const val ACTION_CUSTOM_LEFT_FIRST = 1: Int

The adapter key for the first custom control on the left side of the predefined primary controls.

ACTION_CUSTOM_RIGHT_FIRST

Added in 1.1.0
const val ACTION_CUSTOM_RIGHT_FIRST = 4096: Int

The adapter key for the first custom control on the right side of the predefined primary controls.

ACTION_FAST_FORWARD

Added in 1.1.0
const val ACTION_FAST_FORWARD = 128: Int

The adapter key for the fast forward control.

ACTION_PLAY_PAUSE

Added in 1.1.0
const val ACTION_PLAY_PAUSE = 64: Int

The adapter key for the play/pause control.

ACTION_REPEAT

Added in 1.1.0
const val ACTION_REPEAT = 512: Int

The adapter key for the repeat control.

ACTION_REWIND

Added in 1.1.0
const val ACTION_REWIND = 32: Int

The adapter key for the rewind control.

ACTION_SHUFFLE

Added in 1.1.0
const val ACTION_SHUFFLE = 1024: Int

The adapter key for the shuffle control.

ACTION_SKIP_TO_NEXT

Added in 1.1.0
const val ACTION_SKIP_TO_NEXT = 256: Int

The adapter key for the skip to next control.

ACTION_SKIP_TO_PREVIOUS

Added in 1.1.0
const val ACTION_SKIP_TO_PREVIOUS = 16: Int

The adapter key for the skip to previous control.

Public constructors

PlaybackBaseControlGlue

Added in 1.1.0
PlaybackBaseControlGlue(context: Context, impl: T!)

Constructor for the glue.

Parameters
context: Context
impl: T!

Implementation to underlying media player.

Public functions

getArt

Added in 1.1.0
fun getArt(): Drawable?
Returns
Drawable?

The drawable representing cover image.

getBufferedPosition

Added in 1.1.0
fun getBufferedPosition(): Long
Returns
Long

The current buffered position of the media item in milliseconds.

getControlsRow

Added in 1.1.0
fun getControlsRow(): PlaybackControlsRow?

Returns the playback controls row managed by the glue layer.

getCurrentPosition

Added in 1.1.0
fun getCurrentPosition(): Long
Returns
Long

The current position of the media item in milliseconds.

getDuration

Added in 1.1.0
fun getDuration(): Long
Returns
Long

The duration of the media item in milliseconds.

getPlaybackRowPresenter

Added in 1.1.0
fun getPlaybackRowPresenter(): PlaybackRowPresenter?

Returns the playback controls row Presenter managed by the glue layer.

getPlayerAdapter

Added in 1.1.0
fun getPlayerAdapter(): T!

getSubtitle

Added in 1.1.0
fun getSubtitle(): CharSequence?

Return The media subtitle.

getSupportedActions

Added in 1.1.0
fun getSupportedActions(): Long

Returns a bitmask of actions supported by the media player.

getTitle

Added in 1.1.0
fun getTitle(): CharSequence?

Returns the title of the media item.

isControlsOverlayAutoHideEnabled

Added in 1.1.0
fun isControlsOverlayAutoHideEnabled(): Boolean

Returns true if the controls auto hides after a timeout when media is playing.

isPlaying

Added in 1.2.0-alpha04
fun isPlaying(): Boolean

Returns true if media is currently playing.

isPrepared

Added in 1.2.0-alpha04
fun isPrepared(): Boolean

Returns true when the media player is prepared to start media playback. When returning false, app may listen to onPreparedStateChanged event.

Returns
Boolean

True if prepared, false otherwise.

next

fun next(): Unit

Goes to the next media item. This method is optional.

onActionClicked

abstract fun onActionClicked(action: Action): Unit

Handles action clicks. A subclass may override this add support for additional actions.

onKey

abstract fun onKey(v: View!, keyCode: Int, event: KeyEvent!): Boolean

Handles key events and returns true if handled. A subclass may override this to provide additional support.

pause

fun pause(): Unit

Pauses the media player.

play

fun play(): Unit

Starts the media player. Does nothing if isPrepared is false. To wait isPrepared to be true before playing, use playWhenPrepared.

previous

fun previous(): Unit

Goes to the previous media item. This method is optional.

seekTo

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

Seek media to a new position.

Parameters
position: Long

New position.

setArt

Added in 1.1.0
fun setArt(cover: Drawable?): Unit

Sets the drawable representing cover image. The drawable will be rendered by default description presenter in setDescriptionPresenter.

Parameters
cover: Drawable?

The drawable representing cover image.

setControlsOverlayAutoHideEnabled

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

Sets the controls to auto hide after a timeout when media is playing.

Parameters
enable: Boolean

True to enable auto hide after a timeout when media is playing.

setControlsRow

Added in 1.1.0
fun setControlsRow(controlsRow: PlaybackControlsRow): Unit

Sets the controls row to be managed by the glue layer. If getPrimaryActionsAdapter is not provided, a default ArrayObjectAdapter will be created and initialized in onCreatePrimaryActions. If getSecondaryActionsAdapter is not provided, a default ArrayObjectAdapter will be created and initialized in onCreateSecondaryActions. The primary actions and playback state related aspects of the row are updated by the glue.

setPlaybackRowPresenter

Added in 1.1.0
fun setPlaybackRowPresenter(presenter: PlaybackRowPresenter?): Unit

Sets the controls row Presenter to be managed by the glue layer.

setSubtitle

Added in 1.1.0
fun setSubtitle(subtitle: CharSequence?): Unit

Sets the media subtitle. The subtitle will be rendered by default description presenter setDescriptionPresenter.

Parameters
subtitle: CharSequence?

Subtitle to set.

setTitle

Added in 1.1.0
fun setTitle(title: CharSequence?): Unit

Sets the media title. The title will be rendered by default description presenter setDescriptionPresenter.

Protected functions

notifyItemChanged

Added in 1.1.0
protected java-static fun notifyItemChanged(adapter: ArrayObjectAdapter, object: Any): Unit

onAttachedToHost

protected fun onAttachedToHost(host: PlaybackGlueHost): Unit

This method is called attached to associated PlaybackGlueHost. Subclass may override and call super.onAttachedToHost().

onCreatePrimaryActions

Added in 1.1.0
protected fun onCreatePrimaryActions(primaryActionsAdapter: ArrayObjectAdapter): Unit

May be overridden to add primary actions to the adapter. Default implementation add PlaybackControlsRow.PlayPauseAction.

Parameters
primaryActionsAdapter: ArrayObjectAdapter

The adapter to add primary Actions.

onCreateRowPresenter

Added in 1.1.0
protected abstract fun onCreateRowPresenter(): PlaybackRowPresenter

onCreateSecondaryActions

Added in 1.1.0
protected fun onCreateSecondaryActions(secondaryActionsAdapter: ArrayObjectAdapter): Unit

May be overridden to add secondary actions to the adapter.

Parameters
secondaryActionsAdapter: ArrayObjectAdapter

The adapter you need to add the Actions to.

onDetachedFromHost

protected fun onDetachedFromHost(): Unit

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

onHostStart

protected fun onHostStart(): Unit

This method is called when PlaybackGlueHost is started. Subclass may override.

onHostStop

protected fun onHostStop(): Unit

This method is called when PlaybackGlueHost is stopped. Subclass may override.

onMetadataChanged

Added in 1.1.0
protected fun onMetadataChanged(): Unit

Event when metadata changed

onPlayCompleted

Added in 1.1.0
@CallSuper
protected fun onPlayCompleted(): Unit

Event when play finishes, subclass may handling repeat mode here.

onPlayStateChanged

Added in 1.1.0
@CallSuper
protected fun onPlayStateChanged(): Unit

Event when play state changed.

onPreparedStateChanged

Added in 1.1.0
@CallSuper
protected fun onPreparedStateChanged(): Unit

Event when ready state for play changes.

onUpdateBufferedProgress

Added in 1.1.0
@CallSuper
protected fun onUpdateBufferedProgress(): Unit

onUpdateDuration

Added in 1.1.0
@CallSuper
protected fun onUpdateDuration(): Unit

onUpdateProgress

Added in 1.1.0
@CallSuper
protected fun onUpdateProgress(): Unit