PlaybackControlGlue

public abstract class PlaybackControlGlue
extends PlaybackGlue implements OnActionClickedListener, View.OnKeyListener

java.lang.Object
   ↳ 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(SparseArrayObjectAdapter). 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(Action).

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(boolean) to manage the lifecycle of a periodic callback to updateProgress(). getUpdatePeriod() provides a recommended update period.

Summary

Constants

int ACTION_CUSTOM_LEFT_FIRST

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

int ACTION_CUSTOM_RIGHT_FIRST

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

int ACTION_FAST_FORWARD

The adapter key for the fast forward control.

int ACTION_PLAY_PAUSE

The adapter key for the play/pause control.

int ACTION_REWIND

The adapter key for the rewind control.

int ACTION_SKIP_TO_NEXT

The adapter key for the skip to next control.

int ACTION_SKIP_TO_PREVIOUS

The adapter key for the skip to previous control.

int PLAYBACK_SPEED_FAST_L0

The initial (level 0) fast forward playback speed.

int PLAYBACK_SPEED_FAST_L1

The level 1 fast forward playback speed.

int PLAYBACK_SPEED_FAST_L2

The level 2 fast forward playback speed.

int PLAYBACK_SPEED_FAST_L3

The level 3 fast forward playback speed.

int PLAYBACK_SPEED_FAST_L4

The level 4 fast forward playback speed.

int PLAYBACK_SPEED_INVALID

Invalid playback speed.

int PLAYBACK_SPEED_NORMAL

Speed representing playback state that is playing normally.

int PLAYBACK_SPEED_PAUSED

Speed representing playback state that is paused.

Public constructors

PlaybackControlGlue(Context context, int[] seekSpeeds)

Constructor for the glue.

PlaybackControlGlue(Context context, int[] fastForwardSpeeds, int[] rewindSpeeds)

Constructor for the glue.

Public methods

void enableProgressUpdating(boolean enable)

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

PlaybackControlsRow getControlsRow()

Returns the playback controls row managed by the glue layer.

PlaybackControlsRowPresenter getControlsRowPresenter()

This method is deprecated. PlaybackControlGlue supports any PlaybackRowPresenter, use getPlaybackRowPresenter().

abstract int getCurrentPosition()

Returns the current position of the media item in milliseconds.

abstract int getCurrentSpeedId()

Returns the current playback speed.

int[] getFastForwardSpeeds()

Returns the fast forward speeds.

abstract Drawable getMediaArt()

Returns a bitmap of the art for the