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 | |
---|---|
Constructor for the glue. |
|
Constructor for the glue. |
Public methods | |
---|---|
open Unit |
enableProgressUpdating(enable: Boolean) Override this to start/stop a runnable to call |
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 |
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 |
onActionClicked(action: Action!) Handles action clicks. |
open Boolean |
Handles key events and returns true if handled. |
open Unit |
Start playback at the given speed. |
Unit |
play() |
open Unit |
setControlsRow(controlsRow: PlaybackControlsRow!) Sets the controls row to be managed by the glue layer. |
open Unit |
setControlsRowPresenter(presenter: PlaybackControlsRowPresenter!) Sets the controls row Presenter to be managed by the glue layer. |
open Unit |
setFadingEnabled(enable: Boolean) Sets the controls to fade after a timeout when media is playing. |
open Unit |
setPlaybackRowPresenter(presenter: PlaybackRowPresenter!) Sets the controls row Presenter to be passed to |
open Unit |
Updates the progress bar based on the current media playback position. |
Protected methods | |
---|---|
open Unit |
onAttachedToHost(host: PlaybackGlueHost!) |
open Unit |
Instantiating a |
open Unit |
onCreatePrimaryActions(primaryActionsAdapter: SparseArrayObjectAdapter!) 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 |