belongs to Maven artifact com.android.support:leanback-v17:28.0.0-alpha1
PlaybackControlGlue
public
abstract
class
PlaybackControlGlue
extends PlaybackGlue
implements
OnActionClickedListener,
View.OnKeyListener
java.lang.Object | ||
↳ | android.support.v17.leanback.media.PlaybackGlue | |
↳ | android.support.v17.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
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 |
PlaybackControlsRow
|
getControlsRow()
Returns the playback controls row managed by the glue layer. |
PlaybackControlsRowPresenter
|
getControlsRowPresenter()
This method was deprecated
in API level 25.4.0.
PlaybackControlGlue supports any PlaybackRowPresenter, use
|
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 media item. |
abstract
int
|
getMediaDuration()
Returns the duration of the media item in milliseconds. |
abstract
CharSequence
|
getMediaSubtitle()
Returns the subtitle of the media item. |
abstract
CharSequence
|
getMediaTitle()
Returns the title of the media item. |
PlaybackRowPresenter
|
getPlaybackRowPresenter()
Returns the playback row Presenter to be passed to |
int[]
|
getRewindSpeeds()
Returns the rewind speeds. |
abstract
long
|
getSupportedActions()
Returns a bitmask of actions supported by the media player. |
int
|
getUpdatePeriod()
Returns the time period in milliseconds that should be used to update the progress. |
abstract
boolean
|
hasValidMedia()
Returns true if there is a valid media item. |
boolean
|
isFadingEnabled()
Returns true if controls are set to fade when media is playing. |
abstract
boolean
|
isMediaPlaying()
Returns true if media is currently playing. |
boolean
|
isPlaying()
Returns true if media is currently playing. |
void
|
onActionClicked(Action action)
Handles action clicks. |
boolean
|
onKey(View v, int keyCode, KeyEvent event)
Handles key events and returns true if handled. |
void
|
play(int speed)
Start playback at the given speed. |
final
void
|
play()
Starts the media player. |
void
|
setControlsRow(PlaybackControlsRow controlsRow)
Sets the controls row to be managed by the glue layer. |
void
|
setControlsRowPresenter(PlaybackControlsRowPresenter presenter)
This method was deprecated
in API level 25.4.0.
PlaybackControlGlue supports any PlaybackRowPresenter, use
|
void
|
setFadingEnabled(boolean enable)
Sets the controls to fade after a timeout when media is playing. |
void
|
setPlaybackRowPresenter(PlaybackRowPresenter presenter)
Sets the controls row Presenter to be passed to |
void
|
updateProgress()
Updates the progress bar based on the current media playback position. |
Protected methods | |
---|---|
void
|
onAttachedToHost(PlaybackGlueHost host)
This method is called attached to associated |
void
|
onCreateControlsRowAndPresenter()
Instantiating a |
void
|
onCreatePrimaryActions(SparseArrayObjectAdapter primaryActionsAdapter)
May be overridden to add primary actions to the adapter. |
void
|
onCreateSecondaryActions(ArrayObjectAdapter secondaryActionsAdapter)
May be overridden to add secondary actions to the adapter. |
void
|
onDetachedFromHost()
This method is called when current associated |
void
|
onHostStart()
This method is called when {@link PlaybackGlueHost is started. |
void
|
onHostStop()
This method is called when {@link PlaybackGlueHost is stopped. |
void
|
onMetadataChanged()
Must be called appropriately by a subclass when the metadata state has changed. |
void
|
onStateChanged()
Must be called appropriately by a subclass when the playback state has changed. |
Inherited methods | |
---|---|
![]()
android.support.v17.leanback.media.PlaybackGlue
|