public
abstract
class
PlaybackControlGlue
extends Object
implements
OnActionClickedListener,
View.OnKeyListener
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 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. |
|
PlaybackControlGlue(Context context, PlaybackOverlayFragment fragment, int[] seekSpeeds)
Constructor for the glue. |
|
PlaybackControlGlue(Context context, PlaybackOverlayFragment fragment, int[] fastForwardSpeeds, int[] rewindSpeeds)
Constructor for the glue. |
Public methods | |
---|---|
PlaybackControlsRowPresenter
|
createControlsRowAndPresenter()
Helper method for instantiating a
|
void
|
enableProgressUpdating(boolean enable)
Override this to start/stop a runnable to call |
Context
|
getContext()
Returns the context. |
PlaybackControlsRow
|
getControlsRow()
Returns the playback controls row managed by the glue layer. |
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. |
PlaybackOverlayFragment
|
getFragment()
Returns the fragment. |
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. |
OnItemViewClickedListener
|
getOnItemViewClickedListener()
Returns the |
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. |
void
|
onActionClicked(Action action)
Handles action clicks. |
boolean
|
onKey(View v, int keyCode, KeyEvent event)
Handles key events and returns true if handled. |
void
|
setControlsRow(PlaybackControlsRow controlsRow)
Sets the controls row to be managed by the glue layer. |
void
|
setFadingEnabled(boolean enable)
Sets the controls to fade after a timeout when media is playing. |
void
|
setOnItemViewClickedListener(OnItemViewClickedListener listener)
This method is deprecated.
Don't call this. Instead set the listener on the fragment yourself,
and call |
void
|
updateProgress()
Updates the progress bar based on the current media playback position. |
Protected methods | |
---|---|
SparseArrayObjectAdapter
|
createPrimaryActionsAdapter(PresenterSelector presenterSelector)
Creates the primary action adapter. |
void
|
onMetadataChanged()
Must be called appropriately by a subclass when the metadata state has changed. |
abstract
void
|
onRowChanged(PlaybackControlsRow row)
Invoked when the playback controls row has changed. |
void
|
onStateChanged()
Must be called appropriately by a subclass when the playback state has changed. |
abstract
void
|
pausePlayback()
Pause playback. |
abstract
void
|
skipToNext()
Skip to the next track. |
abstract
void
|
skipToPrevious()
Skip to the previous track. |
abstract
void
|
startPlayback(int speed)
Start playback at the given speed. |
Inherited methods | |
---|---|
From
class
java.lang.Object
| |
From
interface
android.support.v17.leanback.widget.OnActionClickedListener
| |
From
interface
android.view.View.OnKeyListener
|
int ACTION_CUSTOM_LEFT_FIRST
The adapter key for the first custom control on the left side of the predefined primary controls.
Constant Value: 1 (0x00000001)
int ACTION_CUSTOM_RIGHT_FIRST
The adapter key for the first custom control on the right side of the predefined primary controls.
Constant Value: 4096 (0x00001000)
int ACTION_FAST_FORWARD
The adapter key for the fast forward control.
Constant Value: 128 (0x00000080)
int ACTION_PLAY_PAUSE
The adapter key for the play/pause control.
Constant Value: 64 (0x00000040)
int ACTION_REWIND
The adapter key for the rewind control.
Constant Value: 32 (0x00000020)
int ACTION_SKIP_TO_NEXT
The adapter key for the skip to next control.
Constant Value: 256 (0x00000100)
int ACTION_SKIP_TO_PREVIOUS
The adapter key for the skip to previous control.
Constant Value: 16 (0x00000010)
int PLAYBACK_SPEED_FAST_L0
The initial (level 0) fast forward playback speed. The negative of this value is for rewind at the same speed.
Constant Value: 10 (0x0000000a)
int PLAYBACK_SPEED_FAST_L1
The level 1 fast forward playback speed. The negative of this value is for rewind at the same speed.
Constant Value: 11 (0x0000000b)
int PLAYBACK_SPEED_FAST_L2
The level 2 fast forward playback speed. The negative of this value is for rewind at the same speed.
Constant Value: 12 (0x0000000c)
int PLAYBACK_SPEED_FAST_L3
The level 3 fast forward playback speed. The negative of this value is for rewind at the same speed.
Constant Value: 13 (0x0000000d)
int PLAYBACK_SPEED_FAST_L4
The level 4 fast forward playback speed. The negative of this value is for rewind at the same speed.
Constant Value: 14 (0x0000000e)
int PLAYBACK_SPEED_INVALID
Invalid playback speed.
Constant Value: -1 (0xffffffff)
int PLAYBACK_SPEED_NORMAL
Speed representing playback state that is playing normally.
Constant Value: 1 (0x00000001)
int PLAYBACK_SPEED_PAUSED
Speed representing playback state that is paused.
Constant Value: 0 (0x00000000)
PlaybackControlGlue (Context context, int[] seekSpeeds)
Constructor for the glue.
Parameters | |
---|---|
seekSpeeds |
int :
Array of seek speeds for fast forward and rewind.
|
PlaybackControlGlue (Context context, int[] fastForwardSpeeds, int[] rewindSpeeds)
Constructor for the glue.
Parameters | |
---|---|
fastForwardSpeeds |
int :
Array of seek speeds for fast forward. |
rewindSpeeds |
int :
Array of seek speeds for rewind.
|
PlaybackControlGlue (Context context, PlaybackOverlayFragment fragment, int[] seekSpeeds)
Constructor for the glue.
Parameters | |
---|---|
fragment |
PlaybackOverlayFragment :
Optional; if using a PlaybackOverlayFragment , pass it in. |
seekSpeeds |
int :
Array of seek speeds for fast forward and rewind.
|
PlaybackControlGlue (Context context, PlaybackOverlayFragment fragment, int[] fastForwardSpeeds, int[] rewindSpeeds)
Constructor for the glue.
Parameters | |
---|---|
fragment |
PlaybackOverlayFragment :
Optional; if using a PlaybackOverlayFragment , pass it in. |
fastForwardSpeeds |
int :
Array of seek speeds for fast forward. |
rewindSpeeds |
int :
Array of seek speeds for rewind.
|
PlaybackControlsRowPresenter createControlsRowAndPresenter ()
Helper method for instantiating a
PlaybackControlsRow
and corresponding
PlaybackControlsRowPresenter
.
Returns | |
---|---|
PlaybackControlsRowPresenter |
void enableProgressUpdating (boolean enable)
Override this to start/stop a runnable to call updateProgress()
at
an interval such as getUpdatePeriod()
.
Parameters | |
---|---|
enable |
boolean
|
PlaybackControlsRow getControlsRow ()
Returns the playback controls row managed by the glue layer.
Returns | |
---|---|
PlaybackControlsRow |
int getCurrentPosition ()
Returns the current position of the media item in milliseconds.
Returns | |
---|---|
int |
int getCurrentSpeedId ()
Returns the current playback speed. When playing normally,
PLAYBACK_SPEED_NORMAL
should be returned.
Returns | |
---|---|
int |
int[] getFastForwardSpeeds ()
Returns the fast forward speeds.
Returns | |
---|---|
int[] |
PlaybackOverlayFragment getFragment ()
Returns the fragment.
Returns | |
---|---|
PlaybackOverlayFragment |
Drawable getMediaArt ()
Returns a bitmap of the art for the media item.
Returns | |
---|---|
Drawable |
int getMediaDuration ()
Returns the duration of the media item in milliseconds.
Returns | |
---|---|
int |
CharSequence getMediaSubtitle ()
Returns the subtitle of the media item.
Returns | |
---|---|
CharSequence |
CharSequence getMediaTitle ()
Returns the title of the media item.
Returns | |
---|---|
CharSequence |
OnItemViewClickedListener getOnItemViewClickedListener ()
Returns the OnItemViewClickedListener
.
Returns | |
---|---|
OnItemViewClickedListener |
int[] getRewindSpeeds ()
Returns the rewind speeds.
Returns | |
---|---|
int[] |
long getSupportedActions ()
Returns a bitmask of actions supported by the media player.
Returns | |
---|---|
long |
int getUpdatePeriod ()
Returns the time period in milliseconds that should be used
to update the progress. See updateProgress()
.
Returns | |
---|---|
int |
boolean hasValidMedia ()
Returns true if there is a valid media item.
Returns | |
---|---|
boolean |
boolean isFadingEnabled ()
Returns true if controls are set to fade when media is playing.
Returns | |
---|---|
boolean |
boolean isMediaPlaying ()
Returns true if media is currently playing.
Returns | |
---|---|
boolean |
void onActionClicked (Action action)
Handles action clicks. A subclass may override this add support for additional actions.
Parameters | |
---|---|
action |
Action
|
boolean onKey (View v, int keyCode, KeyEvent event)
Handles key events and returns true if handled. A subclass may override this to provide additional support.
Parameters | |
---|---|
v |
View :
The view the key has been dispatched to. |
keyCode |
int :
The code for the physical key that was pressed |
event |
KeyEvent :
The KeyEvent object containing full information about
the event. |
Returns | |
---|---|
boolean |
True if the listener has consumed the event, false otherwise. |
void setControlsRow (PlaybackControlsRow controlsRow)
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.
Parameters | |
---|---|
controlsRow |
PlaybackControlsRow
|
void setFadingEnabled (boolean enable)
Sets the controls to fade after a timeout when media is playing.
Parameters | |
---|---|
enable |
boolean
|
void setOnItemViewClickedListener (OnItemViewClickedListener listener)
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.
void updateProgress ()
Updates the progress bar based on the current media playback position.
SparseArrayObjectAdapter createPrimaryActionsAdapter (PresenterSelector presenterSelector)
Creates the primary action adapter. May be overridden to add additional primary actions to the adapter.
Parameters | |
---|---|
presenterSelector |
PresenterSelector
|
Returns | |
---|---|
SparseArrayObjectAdapter |
void onMetadataChanged ()
Must be called appropriately by a subclass when the metadata state has changed.
void onRowChanged (PlaybackControlsRow row)
Invoked when the playback controls row has changed. The adapter containing this row should be notified.
Parameters | |
---|---|
row |
PlaybackControlsRow
|
void onStateChanged ()
Must be called appropriately by a subclass when the playback state has changed.
void pausePlayback ()
Pause playback.
void skipToNext ()
Skip to the next track.
void skipToPrevious ()
Skip to the previous track.
void startPlayback (int speed)
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.
|