java.lang.Object | |
↳ | android.support.v17.leanback.app.PlaybackControlGlue |
Known Direct Subclasses |
A helper class for managing a PlaybackControlsRow
and
PlaybackOverlayFragment
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 it 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 MediaControllerGlue
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. Providing a
PlaybackOverlayFragment
is optional.
If you have your own controls row you must pass it to setControlsRow(PlaybackControlsRow)
.
The row will be updated by the glue layer based on the media metadata and playback state.
Alternatively, you may call createControlsRowAndPresenter()
which will set a controls
row and return a row presenter you can use to present the row.
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 createPrimaryActionsAdapter(PresenterSelector)
. 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)
. There is no need to call setOnItemViewClickedListener(OnItemViewClickedListener)
but if you do a click listener will be installed on the fragment and recognized action clicks
will be handled. Your listener will be called only for unhandled actions.
The helper implements a key event handler. If you pass a
PlaybackOverlayFragment
the fragment's input event
handler will be set. 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.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | ACTION_CUSTOM_LEFT_FIRST | The adapter key for the first custom control on the right 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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor for the glue.
| |||||||||||
Constructor for the glue.
| |||||||||||
Constructor for the glue.
| |||||||||||
Constructor for the glue.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Helper method for instantiating a
PlaybackControlsRow and corresponding
PlaybackControlsRowPresenter .
| |||||||||||
Override this to start/stop a runnable to call
updateProgress() at
an interval such as getUpdatePeriod() .
| |||||||||||
Returns the context.
| |||||||||||
Returns the playback controls row managed by the glue layer.
| |||||||||||
Returns the current position of the media item in milliseconds.
| |||||||||||
Returns the current playback speed.
| |||||||||||
Returns the fast forward speeds.
| |||||||||||
Returns the fragment.
| |||||||||||
Returns a bitmap of the art for the media item.
| |||||||||||
Returns the duration of the media item in milliseconds.
| |||||||||||
Returns the subtitle of the media item.
| |||||||||||
Returns the title of the media item.
| |||||||||||
Returns the
OnItemViewClickedListener .
| |||||||||||
Returns the rewind speeds.
| |||||||||||
Returns a bitmask of actions supported by the media player.
| |||||||||||
Returns the time period in milliseconds that should be used
to update the progress.
| |||||||||||
Returns true if there is a valid media item.
| |||||||||||
Returns true if controls are set to fade when media is playing.
| |||||||||||
Returns true if media is currently playing.
| |||||||||||
Handles action clicks.
| |||||||||||
Handles key events and returns true if handled.
| |||||||||||
Sets the controls row to be managed by the glue layer.
| |||||||||||
Sets the controls to fade after a timeout when media is playing.
| |||||||||||
This method is deprecated.
Don't call this. Instead set the listener on the fragment yourself,
and call
onActionClicked(Action) to handle clicks.
| |||||||||||
Updates the progress bar based on the current media playback position.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates the primary action adapter.
| |||||||||||
Must be called appropriately by a subclass when the metadata state has changed.
| |||||||||||
Invoked when the playback controls row has changed.
| |||||||||||
Must be called appropriately by a subclass when the playback state has changed.
| |||||||||||
Pause playback.
| |||||||||||
Skip to the next track.
| |||||||||||
Skip to the previous track.
| |||||||||||
Start playback at the given speed.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
android.support.v17.leanback.widget.OnActionClickedListener
| |||||||||||
From interface
android.view.View.OnKeyListener
|
The adapter key for the first custom control on the right side of the predefined primary controls.
The adapter key for the first custom control on the right side of the predefined primary controls.
The adapter key for the fast forward control.
The adapter key for the play/pause control.
The adapter key for the rewind control.
The adapter key for the skip to next control.
The adapter key for the skip to previous control.
The initial (level 0) fast forward playback speed. The negative of this value is for rewind at the same speed.
The level 1 fast forward playback speed. The negative of this value is for rewind at the same speed.
The level 2 fast forward playback speed. The negative of this value is for rewind at the same speed.
The level 3 fast forward playback speed. The negative of this value is for rewind at the same speed.
The level 4 fast forward playback speed. The negative of this value is for rewind at the same speed.
Invalid playback speed.
Speed representing playback state that is playing normally.
Speed representing playback state that is paused.
Constructor for the glue.
seekSpeeds | Array of seek speeds for fast forward and rewind. |
---|
Constructor for the glue.
fastForwardSpeeds | Array of seek speeds for fast forward. |
---|---|
rewindSpeeds | Array of seek speeds for rewind. |
Constructor for the glue.
fragment | Optional; if using a PlaybackOverlayFragment , pass it in. |
---|---|
seekSpeeds | Array of seek speeds for fast forward and rewind. |
Constructor for the glue.
fragment | Optional; if using a PlaybackOverlayFragment , pass it in. |
---|---|
fastForwardSpeeds | Array of seek speeds for fast forward. |
rewindSpeeds | Array of seek speeds for rewind. |
Helper method for instantiating a
PlaybackControlsRow
and corresponding
PlaybackControlsRowPresenter
.
Override this to start/stop a runnable to call updateProgress()
at
an interval such as getUpdatePeriod()
.
Returns the playback controls row managed by the glue layer.
Returns the current position of the media item in milliseconds.
Returns the current playback speed. When playing normally,
PLAYBACK_SPEED_NORMAL
should be returned.
Returns the fast forward speeds.
Returns the duration of the media item in milliseconds.
Returns the OnItemViewClickedListener
.
Returns the rewind speeds.
Returns a bitmask of actions supported by the media player.
Returns the time period in milliseconds that should be used
to update the progress. See updateProgress()
.
Returns true if there is a valid media item.
Returns true if controls are set to fade when media is playing.
Returns true if media is currently playing.
Handles action clicks. A subclass may override this add support for additional actions.
Handles key events and returns true if handled. A subclass may override this to provide additional support.
v | The view the key has been dispatched to. |
---|---|
keyCode | The code for the physical key that was pressed |
event | The KeyEvent object containing full information about the event. |
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.
Sets the controls to fade after a timeout when media is playing.
This method is deprecated.
Don't call this. Instead set the listener on the fragment yourself,
and call onActionClicked(Action)
to handle clicks.
Set the OnItemViewClickedListener
to be called if the click event
is not handled internally.
Updates the progress bar based on the current media playback position.
Creates the primary action adapter. May be overridden to add additional primary actions to the adapter.
Must be called appropriately by a subclass when the metadata state has changed.
Invoked when the playback controls row has changed. The adapter containing this row should be notified.
Must be called appropriately by a subclass when the playback state has changed.
Pause playback.
Skip to the next track.
Skip to the previous track.
Start playback at the given speed.
speed | The desired playback speed. For normal playback this will be
PLAYBACK_SPEED_NORMAL ; higher positive values for fast forward,
and negative values for rewind.
|
---|