PlaybackBaseControlGlue

abstract class PlaybackBaseControlGlue<T : PlayerAdapter!> : PlaybackGlue, OnActionClickedListener, OnKeyListener
kotlin.Any
   ↳ androidx.leanback.media.PlaybackGlue
   ↳ androidx.leanback.media.PlaybackBaseControlGlue

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(Action).

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

Summary

Constants
static Int

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

static Int

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

static Int

The adapter key for the fast forward control.

static Int

The adapter key for the play/pause control.

static Int

The adapter key for the repeat control.

static Int

The adapter key for the rewind control.

static Int

The adapter key for the shuffle control.

static Int

The adapter key for the skip to next control.

static Int

The adapter key for the skip to previous control.

Public constructors
<init>(context: Context!, impl: T)

Constructor for the glue.

Public methods
Long

open Unit

open Long

open Drawable!

open Unit

open PlaybackRowPresenter!

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

open CharSequence!

Return The media subtitle.

open Unit

Sets the media title.

open CharSequence!

Returns the title of the media item.

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

Handles key events and returns true if handled.

open Long

Returns a bitmask of actions supported by the media player.

Boolean

open Unit

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

open Unit

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

open Unit
setArt(cover: Drawable!)

Sets the drawable representing cover image.

Long

abstract Unit

Handles action clicks.

Unit
seekTo(position: Long)

Seek media to a new position.

T

open Unit

open Unit

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

open Unit

Sets the media subtitle.

Boolean

open Boolean

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

open Unit

open PlaybackControlsRow!

Returns the playback controls row managed by the glue layer.

Protected methods
open Unit
onCreateSecondaryActions(secondaryActionsAdapter: ArrayObjectAdapter!)

May be overridden to add secondary actions to the adapter.

open Unit

open Unit

open Unit
onCreatePrimaryActions(primaryActionsAdapter: ArrayObjectAdapter!)

May be overridden to add primary actions to the adapter.

open Unit

Event when ready state for play changes.

open Unit

open Unit

open Unit

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

open Unit

Event when play state changed.

open Unit

open Unit

Event when metadata changed

open Unit

abstract PlaybackRowPresenter!

open Unit

open static Unit

Inherited functions

Constants

ACTION_CUSTOM_LEFT_FIRST

static val ACTION_CUSTOM_LEFT_FIRST: Int

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

Value: 1

ACTION_CUSTOM_RIGHT_FIRST

static val ACTION_CUSTOM_RIGHT_FIRST: Int

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

Value: 4096

ACTION_FAST_FORWARD

static val ACTION_FAST_FORWARD: Int

The adapter key for the fast forward control.

Value: 128

ACTION_PLAY_PAUSE

static val ACTION_PLAY_PAUSE: Int

The adapter key for the play/pause control.

Value: 64

ACTION_REPEAT

static val ACTION_REPEAT: Int

The adapter key for the repeat control.

Value: 512

ACTION_REWIND

static val ACTION_REWIND: Int

The adapter key for the rewind control.

Value: 32

ACTION_SHUFFLE

static val ACTION_SHUFFLE: Int

The adapter key for the shuffle control.

Value: 1024

ACTION_SKIP_TO_NEXT

static val ACTION_SKIP_TO_NEXT: Int

The adapter key for the skip to next control.

Value: 256

ACTION_SKIP_TO_PREVIOUS

static val ACTION_SKIP_TO_PREVIOUS: Int

The adapter key for the skip to previous control.

Value: 16

Public constructors

<init>

PlaybackBaseControlGlue(context: Context!, impl: T)

Constructor for the glue.

Parameters
context Context!:
impl Context!: Implementation to underlying media player.

Public methods

getDuration

fun getDuration(): Long
Return
Long: The duration of the media item in milliseconds.

previous

open fun previous(): Unit

getCurrentPosition

open fun getCurrentPosition(): Long
Return
Long: The current position of the media item in milliseconds.

getArt

open fun getArt(): Drawable!
Return
Drawable!: The drawable representing cover image.

play

open fun play(): Unit

getPlaybackRowPresenter

open fun getPlaybackRowPresenter(): PlaybackRowPresenter!

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

getSubtitle

open fun getSubtitle(): CharSequence!

Return The media subtitle.

setTitle

open fun setTitle(title: CharSequence!): Unit

Sets the media title. The title will be rendered by default description presenter PlaybackTransportRowPresenter#setDescriptionPresenter(Presenter).

getTitle

open fun getTitle(): CharSequence!

Returns the title of the media item.

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.

getSupportedActions

open fun getSupportedActions(): Long

Returns a bitmask of actions supported by the media player.

isPrepared

fun isPrepared(): Boolean

setControlsOverlayAutoHideEnabled

open 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

open fun setControlsRow(controlsRow: PlaybackControlsRow!): Unit

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

setArt

open fun setArt(cover: Drawable!): Unit

Sets the drawable representing cover image. The drawable will be rendered by default description presenter in PlaybackTransportRowPresenter#setDescriptionPresenter(Presenter).

Parameters
cover Drawable!: The drawable representing cover image.

getBufferedPosition

fun getBufferedPosition(): Long
Return
Long: The current buffered position of the media item in milliseconds.

onActionClicked

abstract fun onActionClicked(action: Action!): Unit

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

seekTo

fun seekTo(position: Long): Unit

Seek media to a new position.

Parameters
position Long: New position.

getPlayerAdapter

fun getPlayerAdapter(): T

next

open fun next(): Unit

setPlaybackRowPresenter

open fun setPlaybackRowPresenter(presenter: PlaybackRowPresenter!): Unit

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

setSubtitle

open fun setSubtitle(subtitle: CharSequence!): Unit

Sets the media subtitle. The subtitle will be rendered by default description presenter PlaybackTransportRowPresenter#setDescriptionPresenter(Presenter).

Parameters
subtitle CharSequence!: Subtitle to set.

isPlaying

fun isPlaying(): Boolean

isControlsOverlayAutoHideEnabled

open fun isControlsOverlayAutoHideEnabled(): Boolean

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

pause

open fun pause(): Unit

getControlsRow

open fun getControlsRow(): PlaybackControlsRow!

Returns the playback controls row managed by the glue layer.

Protected methods

onCreateSecondaryActions

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

onHostStop

protected open fun onHostStop(): Unit

onHostStart

protected open fun onHostStart(): Unit

onCreatePrimaryActions

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

onPreparedStateChanged

protected open fun onPreparedStateChanged(): Unit

Event when ready state for play changes.

onDetachedFromHost

protected open fun onDetachedFromHost(): Unit

onUpdateBufferedProgress

protected open fun onUpdateBufferedProgress(): Unit

onPlayCompleted

protected open fun onPlayCompleted(): Unit

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

onPlayStateChanged

protected open fun onPlayStateChanged(): Unit

Event when play state changed.

onUpdateDuration

protected open fun onUpdateDuration(): Unit

onMetadataChanged

protected open fun onMetadataChanged(): Unit

Event when metadata changed

onUpdateProgress

protected open fun onUpdateProgress(): Unit

onCreateRowPresenter

protected abstract fun onCreateRowPresenter(): PlaybackRowPresenter!

onAttachedToHost

protected open fun onAttachedToHost(host: PlaybackGlueHost!): Unit

notifyItemChanged

protected open static fun notifyItemChanged(adapter: ArrayObjectAdapter!, object: Any!): Unit