Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

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
open Drawable!

Long

open PlaybackControlsRow!

Returns the playback controls row managed by the glue layer.

open Long

Long

open PlaybackRowPresenter!

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

T

open CharSequence!

Return The media subtitle.

open Long

Returns a bitmask of actions supported by the media player.

open CharSequence!

Returns the title of the media item.

open Boolean

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

Boolean

Boolean

open Unit

abstract Unit

Handles action clicks.

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

Handles key events and returns true if handled.

open Unit

open Unit

open Unit

Unit
seekTo(position: Long)

Seek media to a new position.

open Unit
setArt(cover: Drawable!)

Sets the drawable representing cover image.

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

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

open Unit

Sets the media subtitle.

open Unit

Sets the media title.

Protected methods
open static Unit

open Unit

open Unit
onCreatePrimaryActions(primaryActionsAdapter: ArrayObjectAdapter!)

May be overridden to add primary actions to the adapter.

abstract PlaybackRowPresenter!

open Unit
onCreateSecondaryActions(secondaryActionsAdapter: ArrayObjectAdapter!)

May be overridden to add secondary actions to the adapter.

open Unit

open Unit

open Unit

open Unit

Event when metadata changed

open Unit

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

open Unit

Event when play state changed.

open Unit

Event when ready state for play changes.

open Unit

open Unit

open 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: 0x1

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: 0x1000

ACTION_FAST_FORWARD

static val ACTION_FAST_FORWARD: Int

The adapter key for the fast forward control.

Value: 0x80

ACTION_PLAY_PAUSE

static val ACTION_PLAY_PAUSE: Int

The adapter key for the play/pause control.

Value: 0x40

ACTION_REPEAT

static val ACTION_REPEAT: Int

The adapter key for the repeat control.

Value: 0x200

ACTION_REWIND

static val ACTION_REWIND: Int

The adapter key for the rewind control.

Value: 0x20

ACTION_SHUFFLE

static val ACTION_SHUFFLE: Int

The adapter key for the shuffle control.

Value: 0x400

ACTION_SKIP_TO_NEXT

static val ACTION_SKIP_TO_NEXT: Int

The adapter key for the skip to next control.

Value: 0x100

ACTION_SKIP_TO_PREVIOUS

static val ACTION_SKIP_TO_PREVIOUS: Int

The adapter key for the skip to previous control.

Value: 0x10

Public constructors

<init>

PlaybackBaseControlGlue(context: Context!, impl: T)

Constructor for the glue.

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

Public methods

getArt

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

getBufferedPosition

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

getControlsRow

open fun getControlsRow(): PlaybackControlsRow!

Returns the playback controls row managed by the glue layer.

getCurrentPosition

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

getDuration

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

getPlaybackRowPresenter

open fun getPlaybackRowPresenter(): PlaybackRowPresenter!

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

getPlayerAdapter

fun getPlayerAdapter(): T

getSubtitle

open fun getSubtitle(): CharSequence!

Return The media subtitle.

getSupportedActions

open fun getSupportedActions(): Long

Returns a bitmask of actions supported by the media player.

getTitle

open fun getTitle(): CharSequence!

Returns the title of the media item.

isControlsOverlayAutoHideEnabled

open fun isControlsOverlayAutoHideEnabled(): Boolean

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

isPlaying

fun isPlaying(): Boolean

isPrepared

fun isPrepared(): Boolean

next

open fun next(): Unit

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

open fun pause(): Unit

play

open fun play(): Unit

previous

open fun previous(): Unit

seekTo

fun seekTo(position: Long): Unit

Seek media to a new position.

Parameters
position Long: New position.

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.

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.

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.

setTitle

open fun setTitle(title: CharSequence!): Unit

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

Protected methods

notifyItemChanged

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

onAttachedToHost

protected open fun onAttachedToHost(host: PlaybackGlueHost!): 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.

onCreateRowPresenter

protected abstract fun onCreateRowPresenter(): PlaybackRowPresenter!

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.

onDetachedFromHost

protected open fun onDetachedFromHost(): Unit

onHostStart

protected open fun onHostStart(): Unit

onHostStop

protected open fun onHostStop(): Unit

onMetadataChanged

protected open fun onMetadataChanged(): Unit

Event when metadata changed

onPlayCompleted

@CallSuper protected open fun onPlayCompleted(): Unit

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

onPlayStateChanged

@CallSuper protected open fun onPlayStateChanged(): Unit

Event when play state changed.

onPreparedStateChanged

@CallSuper protected open fun onPreparedStateChanged(): Unit

Event when ready state for play changes.

onUpdateBufferedProgress

@CallSuper protected open fun onUpdateBufferedProgress(): Unit

onUpdateDuration

@CallSuper protected open fun onUpdateDuration(): Unit

onUpdateProgress

@CallSuper protected open fun onUpdateProgress(): Unit