PlaybackControlGlue

abstract class PlaybackControlGlue : PlaybackGlue, OnActionClickedListener, OnKeyListener
kotlin.Any
   ↳ androidx.leanback.media.PlaybackGlue
   ↳ androidx.leanback.media.PlaybackControlGlue

A helper class for managing a PlaybackControlsRow and PlaybackGlueHost that implements a recommended approach to handling standard playback control actions such as play/pause, fast forward/rewind at progressive speed levels, and skip to next/previous. This helper class is a glue layer in that manages the configuration of and interaction between the leanback UI components by defining a functional interface to the media player.

You can instantiate a concrete subclass such as MediaPlayerGlue or you must subclass this abstract helper. To create a subclass you must implement all of the abstract methods and the subclass must invoke onMetadataChanged() and onStateChanged() appropriately.

To use an instance of the glue layer, first construct an instance. Constructor parameters inform the glue what speed levels are supported for fast forward/rewind.

You may override onCreateControlsRowAndPresenter() which will create a PlaybackControlsRow and a PlaybackControlsRowPresenter. You may call setControlsRow(PlaybackControlsRow) and setPlaybackRowPresenter(PlaybackRowPresenter) to customize your own row and presenter.

The helper sets a SparseArrayObjectAdapter on the controls row as the primary actions adapter, and adds actions to it. You can provide additional actions by overriding onCreatePrimaryActions. This helper does not deal in secondary actions so those you may add separately.

Provide a click listener on your fragment and if an action is clicked, call onActionClicked.

This helper implements a key event handler. If you pass a PlaybackGlueHost, it will configure its fragment to intercept all key events. Otherwise, you should set the glue object as key event handler to the ViewHolder when bound by your row presenter; see RowPresenter.ViewHolder#setOnKeyListener(android.view.View.OnKeyListener).

To update the controls row progress during playback, override enableProgressUpdating to manage the lifecycle of a periodic callback to updateProgress(). getUpdatePeriod() provides a recommended update period.

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 rewind control.

static Int

The adapter key for the skip to next control.

static Int

The adapter key for the skip to previous control.

static Int

The initial (level 0) fast forward playback speed.

static Int

The level 1 fast forward playback speed.

static Int

The level 2 fast forward playback speed.

static Int

The level 3 fast forward playback speed.

static Int

The level 4 fast forward playback speed.

static Int

Invalid playback speed.

static Int

Speed representing playback state that is playing normally.

static Int

Speed representing playback state that is paused.

Public constructors

<init>(context: Context!, seekSpeeds: IntArray!)

Constructor for the glue.

<init>(context: Context!, fastForwardSpeeds: IntArray!, rewindSpeeds: IntArray!)

Constructor for the glue.

Public methods

open Unit

Override this to start/stop a runnable to call updateProgress at an interval such as getUpdatePeriod.

open PlaybackControlsRow!

Returns the playback controls row managed by the glue layer.

open PlaybackControlsRowPresenter!

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

abstract Int

Returns the current position of the media item in milliseconds.

abstract Int

Returns the current playback speed.

open IntArray!

Returns the fast forward speeds.

abstract Drawable!

Returns a bitmap of the art for the media item.

abstract Int

Returns the duration of the media item in milliseconds.

abstract CharSequence!

Returns the subtitle of the media item.

abstract CharSequence!

Returns the title of the media item.

open PlaybackRowPresenter!

Returns the playback row Presenter to be passed to PlaybackGlueHost in onAttachedToHost(PlaybackGlueHost).

open IntArray!

Returns the rewind speeds.

abstract Long

Returns a bitmask of actions supported by the media player.

open Int

Returns the time period in milliseconds that should be used to update the progress.

abstract Boolean

Returns true if there is a valid media item.

open Boolean

Returns true if controls are set to fade when media is playing.

abstract Boolean

Returns true if media is currently playing.

open Boolean

open Unit

Handles action clicks.

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

Handles key events and returns true if handled.

open Unit
play(speed: Int)

Start playback at the given speed.

Unit

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 controls to fade after a timeout when media is playing.

open Unit

Sets the controls row Presenter to be passed to PlaybackGlueHost in onAttachedToHost(PlaybackGlueHost).

open Unit

Updates the progress bar based on the current media playback position.

Protected methods

open Unit

open Unit

Instantiating a PlaybackControlsRow and corresponding PlaybackControlsRowPresenter.

open Unit

May be overridden to add primary actions to the adapter.

open Unit
onCreateSecondaryActions(secondaryActionsAdapter: ArrayObjectAdapter!)

May be overridden to add secondary actions to the adapter.

open Unit

open Unit

open Unit

open Unit

Must be called appropriately by a subclass when the metadata state has changed.

open Unit

Must be called appropriately by a subclass when the playback state has changed.

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_REWIND

static val ACTION_REWIND: Int

The adapter key for the rewind control.

Value: 0x20

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

PLAYBACK_SPEED_FAST_L0

static val PLAYBACK_SPEED_FAST_L0: Int

The initial (level 0) fast forward playback speed. The negative of this value is for rewind at the same speed.

Value: 10

PLAYBACK_SPEED_FAST_L1

static val PLAYBACK_SPEED_FAST_L1: Int

The level 1 fast forward playback speed. The negative of this value is for rewind at the same speed.

Value: 11

PLAYBACK_SPEED_FAST_L2

static val PLAYBACK_SPEED_FAST_L2: Int

The level 2 fast forward playback speed. The negative of this value is for rewind at the same speed.

Value: 12

PLAYBACK_SPEED_FAST_L3

static val PLAYBACK_SPEED_FAST_L3: Int

The level 3 fast forward playback speed. The negative of this value is for rewind at the same speed.

Value: 13

PLAYBACK_SPEED_FAST_L4

static val PLAYBACK_SPEED_FAST_L4: Int

The level 4 fast forward playback speed. The negative of this value is for rewind at the same speed.

Value: 14

PLAYBACK_SPEED_INVALID

static val PLAYBACK_SPEED_INVALID: Int

Invalid playback speed.

Value: -1

PLAYBACK_SPEED_NORMAL

static val PLAYBACK_SPEED_NORMAL: Int

Speed representing playback state that is playing normally.

Value: 1

PLAYBACK_SPEED_PAUSED

static val PLAYBACK_SPEED_PAUSED: Int

Speed representing playback state that is paused.

Value: 0

Public constructors

<init>

PlaybackControlGlue(context: Context!, seekSpeeds: IntArray!)

Constructor for the glue.

Parameters
context Context!:
seekSpeeds Context!: Array of seek speeds for fast forward and rewind.

<init>

PlaybackControlGlue(context: Context!, fastForwardSpeeds: IntArray!, rewindSpeeds: IntArray!)

Constructor for the glue.

Parameters
context Context!:
fastForwardSpeeds Context!: Array of seek speeds for fast forward.
rewindSpeeds Context!: Array of seek speeds for rewind.

Public methods

enableProgressUpdating

open fun enableProgressUpdating(enable: Boolean): Unit

Override this to start/stop a runnable to call updateProgress at an interval such as getUpdatePeriod.

getControlsRow

open fun getControlsRow(): PlaybackControlsRow!

Returns the playback controls row managed by the glue layer.

getControlsRowPresenter

open fun getControlsRowPresenter(): PlaybackControlsRowPresenter!

Deprecated: PlaybackControlGlue supports any PlaybackRowPresenter, use getPlaybackRowPresenter().

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

getCurrentPosition

abstract fun getCurrentPosition(): Int

Returns the current position of the media item in milliseconds.

getCurrentSpeedId

abstract fun getCurrentSpeedId(): Int

Returns the current playback speed. When playing normally, PLAYBACK_SPEED_NORMAL should be returned.

getFastForwardSpeeds

open fun getFastForwardSpeeds(): IntArray!

Returns the fast forward speeds.

getMediaArt

abstract fun getMediaArt(): Drawable!

Returns a bitmap of the art for the media item.

getMediaDuration

abstract fun getMediaDuration(): Int

Returns the duration of the media item in milliseconds.

getMediaSubtitle

abstract fun getMediaSubtitle(): CharSequence!

Returns the subtitle of the media item.

getMediaTitle

abstract fun getMediaTitle(): CharSequence!

Returns the title of the media item.

getPlaybackRowPresenter

open fun getPlaybackRowPresenter(): PlaybackRowPresenter!

Returns the playback row Presenter to be passed to PlaybackGlueHost in onAttachedToHost(PlaybackGlueHost).

getRewindSpeeds

open fun getRewindSpeeds(): IntArray!

Returns the rewind speeds.

getSupportedActions

abstract fun getSupportedActions(): Long

Returns a bitmask of actions supported by the media player.

getUpdatePeriod

open fun getUpdatePeriod(): Int

Returns the time period in milliseconds that should be used to update the progress. See updateProgress().

hasValidMedia

abstract fun hasValidMedia(): Boolean

Returns true if there is a valid media item.

isFadingEnabled

open fun isFadingEnabled(): Boolean

Returns true if controls are set to fade when media is playing.

isMediaPlaying

abstract fun isMediaPlaying(): Boolean

Returns true if media is currently playing.

isPlaying

open fun isPlaying(): Boolean

onActionClicked

open fun onActionClicked(action: Action!): Unit

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

onKey

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

play

open fun play(speed: Int): Unit

Start playback at the given speed.

Parameters
speed Int: The desired playback speed. For normal playback this will be PLAYBACK_SPEED_NORMAL; higher positive values for fast forward, and negative values for rewind.

play

fun play(): Unit

setControlsRow

open fun setControlsRow(controlsRow: PlaybackControlsRow!): Unit

Sets the controls row to be managed by the glue layer. The primary actions and playback state related aspects of the row are updated by the glue.

setControlsRowPresenter

open fun setControlsRowPresenter(presenter: PlaybackControlsRowPresenter!): Unit

Deprecated: PlaybackControlGlue supports any PlaybackRowPresenter, use setPlaybackRowPresenter(PlaybackRowPresenter).

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

setFadingEnabled

open fun setFadingEnabled(enable: Boolean): Unit

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

setPlaybackRowPresenter

open fun setPlaybackRowPresenter(presenter: PlaybackRowPresenter!): Unit

Sets the controls row Presenter to be passed to PlaybackGlueHost in onAttachedToHost(PlaybackGlueHost).

updateProgress

open fun updateProgress(): Unit

Updates the progress bar based on the current media playback position.

Protected methods

onAttachedToHost

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

onCreateControlsRowAndPresenter

protected open fun onCreateControlsRowAndPresenter(): Unit

Instantiating a PlaybackControlsRow and corresponding PlaybackControlsRowPresenter. Subclass may override.

onCreatePrimaryActions

protected open fun onCreatePrimaryActions(primaryActionsAdapter: SparseArrayObjectAdapter!): Unit

May be overridden to add primary actions to the adapter.

Parameters
primaryActionsAdapter SparseArrayObjectAdapter!: The adapter to add primary Actions.

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

Must be called appropriately by a subclass when the metadata state has changed.

onStateChanged

protected open fun onStateChanged(): Unit

Must be called appropriately by a subclass when the playback state has changed. It updates the playback state displayed on the media player.