PlaybackBaseControlGlue
public
abstract
class
PlaybackBaseControlGlue
extends PlaybackGlue
implements
OnActionClickedListener,
View.OnKeyListener
java.lang.Object | ||
↳ | androidx.leanback.media.PlaybackGlue | |
↳ | androidx.leanback.media.PlaybackBaseControlGlue<T extends androidx.leanback.media.PlayerAdapter> |
A base abstract class for managing a PlaybackControlsRow
being displayed in
PlaybackGlueHost
. It supports standard playback control actions play/pause and
skip next/previous. This helper class is a glue layer that manages interaction between the
leanback UI components PlaybackControlsRow
PlaybackRowPresenter
and a functional PlayerAdapter
which represents the underlying
media player.
The app must pass a PlayerAdapter
in constructor for a specific
implementation e.g. a MediaPlayerAdapter
.
The glue has two action bars: primary action bars and secondary action bars. Apps
can provide additional actions by overriding onCreatePrimaryActions(ArrayObjectAdapter)
and / or
onCreateSecondaryActions(ArrayObjectAdapter)
and respond to actions by overriding
onActionClicked(Action)
.
The subclass is responsible for implementing the "repeat mode" in
onPlayCompleted()
.
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_REPEAT
The adapter key for the repeat control. |
int |
ACTION_REWIND
The adapter key for the rewind control. |
int |
ACTION_SHUFFLE
The adapter key for the shuffle 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. |
Public constructors | |
---|---|
PlaybackBaseControlGlue(Context context, T impl)
Constructor for the glue. |
Public methods | |
---|---|
Drawable
|
getArt()
|
final
long
|
getBufferedPosition()
|
PlaybackControlsRow
|
getControlsRow()
Returns the playback controls row managed by the glue layer. |
long
|
getCurrentPosition()
|
final
long
|
getDuration()
|
PlaybackRowPresenter
|
getPlaybackRowPresenter()
Returns the playback controls row Presenter managed by the glue layer. |
final
T
|
getPlayerAdapter()
|
CharSequence
|
getSubtitle()
Return The media subtitle. |
long
|
getSupportedActions()
Returns a bitmask of actions supported by the media player. |
CharSequence
|
getTitle()
Returns the title of the media item. |
boolean
|
isControlsOverlayAutoHideEnabled()
Returns true if the controls auto hides after a timeout when media is playing. |
final
boolean
|
isPlaying()
Returns true if media is currently playing. |
final
boolean
|
isPrepared()
Returns true when the media player is prepared to start media playback. |
void
|
next()
Goes to the next media item. |
abstract
void
|
onActionClicked(Action action)
Handles action clicks. |
abstract
boolean
|
onKey(View v, int keyCode, KeyEvent event)
Handles key events and returns true if handled. |
void
|
pause()
Pauses the media player. |
void
|
play()
Starts the media player. |
void
|
previous()
Goes to the previous media item. |
final
void
|
seekTo(long position)
Seek media to a new position. |
void
|
setArt(Drawable cover)
Sets the drawable representing cover image. |
void
|
setControlsOverlayAutoHideEnabled(boolean enable)
Sets the controls to auto hide after a timeout when media is playing. |
void
|
setControlsRow(PlaybackControlsRow controlsRow)
Sets the controls row to be managed by the glue layer. |
void
|
setPlaybackRowPresenter(PlaybackRowPresenter presenter)
Sets the controls row Presenter to be managed by the glue layer. |
void
|
setSubtitle(CharSequence subtitle)
Sets the media subtitle. |
void
|
setTitle(CharSequence title)
Sets the media title. |
Protected methods | |
---|---|
static
void
|
notifyItemChanged(ArrayObjectAdapter adapter, Object object)
|
void
|
onAttachedToHost(PlaybackGlueHost host)
This method is called attached to associated |
void
|
onCreatePrimaryActions(ArrayObjectAdapter primaryActionsAdapter)
May be overridden to add primary actions to the adapter. |
abstract
PlaybackRowPresenter
|
onCreateRowPresenter()
|
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 |
void
|
onHostStop()
This method is called when |
void
|
onMetadataChanged()
Event when metadata changed |
void
|
onPlayCompleted()
Event when play finishes, subclass may handling repeat mode here. |
void
|
onPlayStateChanged()
Event when play state changed. |
void
|
onPreparedStateChanged()
Event when ready state for play changes. |
void
|
onUpdateBufferedProgress()
|
void
|
onUpdateDuration()
|
void
|
onUpdateProgress()
|
Inherited methods | |
---|---|
Constants
ACTION_CUSTOM_LEFT_FIRST
public static final 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)
ACTION_CUSTOM_RIGHT_FIRST
public static final 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)
ACTION_FAST_FORWARD
public static final int ACTION_FAST_FORWARD
The adapter key for the fast forward control.
Constant Value: 128 (0x00000080)
ACTION_PLAY_PAUSE
public static final int ACTION_PLAY_PAUSE
The adapter key for the play/pause control.
Constant Value: 64 (0x00000040)
ACTION_REPEAT
public static final int ACTION_REPEAT
The adapter key for the repeat control.
Constant Value: 512 (0x00000200)
ACTION_REWIND
public static final int ACTION_REWIND
The adapter key for the rewind control.
Constant Value: 32 (0x00000020)
ACTION_SHUFFLE
public static final int ACTION_SHUFFLE
The adapter key for the shuffle control.
Constant Value: 1024 (0x00000400)
ACTION_SKIP_TO_NEXT
public static final int ACTION_SKIP_TO_NEXT
The adapter key for the skip to next control.
Constant Value: 256 (0x00000100)
ACTION_SKIP_TO_PREVIOUS
public static final int ACTION_SKIP_TO_PREVIOUS
The adapter key for the skip to previous control.
Constant Value: 16 (0x00000010)
Public constructors
PlaybackBaseControlGlue
public PlaybackBaseControlGlue (Context context, T impl)
Constructor for the glue.
Parameters | |
---|---|
impl |
T : Implementation to underlying media player.
|
Public methods
getBufferedPosition
public final long getBufferedPosition ()
Returns | |
---|---|
long |
The current buffered position of the media item in milliseconds. |
getControlsRow
public PlaybackControlsRow getControlsRow ()
Returns the playback controls row managed by the glue layer.
Returns | |
---|---|
PlaybackControlsRow |
getCurrentPosition
public long getCurrentPosition ()
Returns | |
---|---|
long |
The current position of the media item in milliseconds. |
getDuration
public final long getDuration ()
Returns | |
---|---|
long |
The duration of the media item in milliseconds. |
getPlaybackRowPresenter
public PlaybackRowPresenter getPlaybackRowPresenter ()
Returns the playback controls row Presenter managed by the glue layer.
Returns | |
---|---|
PlaybackRowPresenter |
getPlayerAdapter
public final T getPlayerAdapter ()
Returns | |
---|---|
T |
getSubtitle
public CharSequence getSubtitle ()
Return The media subtitle.
Returns | |
---|---|
CharSequence |
getSupportedActions
public long getSupportedActions ()
Returns a bitmask of actions supported by the media player.
Returns | |
---|---|
long |
getTitle
public CharSequence getTitle ()
Returns the title of the media item.
Returns | |
---|---|
CharSequence |
isControlsOverlayAutoHideEnabled
public boolean isControlsOverlayAutoHideEnabled ()
Returns true if the controls auto hides after a timeout when media is playing.
Returns | |
---|---|
boolean |
isPlaying
public final boolean isPlaying ()
Returns true if media is currently playing.
Returns | |
---|---|
boolean |
isPrepared
public final boolean isPrepared ()
Returns true when the media player is prepared to start media playback. When returning false,
app may listen to PlaybackGlue.PlayerCallback.onPreparedStateChanged(PlaybackGlue)
event.
Returns | |
---|---|
boolean |
True if prepared, false otherwise. |
next
public void next ()
Goes to the next media item. This method is optional.
onActionClicked
public abstract void onActionClicked (Action action)
Handles action clicks. A subclass may override this add support for additional actions.
Parameters | |
---|---|
action |
Action |
onKey
public abstract 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 |
keyCode |
int |
event |
KeyEvent |
Returns | |
---|---|
boolean |
pause
public void pause ()
Pauses the media player.
play
public void play ()
Starts the media player. Does nothing if isPrepared()
is false. To wait
isPrepared()
to be true before playing, use playWhenPrepared()
.
previous
public void previous ()
Goes to the previous media item. This method is optional.
seekTo
public final void seekTo (long position)
Seek media to a new position.
Parameters | |
---|---|
position |
long : New position.
|
setArt
public void setArt (Drawable cover)
Sets the drawable representing cover image. The drawable will be rendered by default
description presenter in
PlaybackTransportRowPresenter.setDescriptionPresenter(Presenter)
.
Parameters | |
---|---|
cover |
Drawable : The drawable representing cover image.
|
setControlsOverlayAutoHideEnabled
public void setControlsOverlayAutoHideEnabled (boolean enable)
Sets the controls to auto hide after a timeout when media is playing.
Parameters | |
---|---|
enable |
boolean : True to enable auto hide after a timeout when media is playing. |
setControlsRow
public void setControlsRow (PlaybackControlsRow controlsRow)
Sets the controls row to be managed by the glue layer. If
PlaybackControlsRow.getPrimaryActionsAdapter()
is not provided, a default
ArrayObjectAdapter
will be created and initialized in
onCreatePrimaryActions(ArrayObjectAdapter)
. If
PlaybackControlsRow.getSecondaryActionsAdapter()
is not provided, a default
ArrayObjectAdapter
will be created and initialized in
onCreateSecondaryActions(ArrayObjectAdapter)
.
The primary actions and playback state related aspects of the row
are updated by the glue.
Parameters | |
---|---|
controlsRow |
PlaybackControlsRow |
setPlaybackRowPresenter
public void setPlaybackRowPresenter (PlaybackRowPresenter presenter)
Sets the controls row Presenter to be managed by the glue layer.
Parameters | |
---|---|
presenter |
PlaybackRowPresenter |
setSubtitle
public void setSubtitle (CharSequence subtitle)
Sets the media subtitle. The subtitle will be rendered by default description presenter
PlaybackTransportRowPresenter.setDescriptionPresenter(Presenter)
.
Parameters | |
---|---|
subtitle |
CharSequence : Subtitle to set.
|
setTitle
public void setTitle (CharSequence title)
Sets the media title. The title will be rendered by default description presenter
PlaybackTransportRowPresenter.setDescriptionPresenter(Presenter)
.
Parameters | |
---|---|
title |
CharSequence |
Protected methods
notifyItemChanged
protected static void notifyItemChanged (ArrayObjectAdapter adapter, Object object)
Parameters | |
---|---|
adapter |
ArrayObjectAdapter |
object |
Object |
onAttachedToHost
protected void onAttachedToHost (PlaybackGlueHost host)
This method is called attached to associated PlaybackGlueHost
. Subclass may override
and call super.onAttachedToHost().
Parameters | |
---|---|
host |
PlaybackGlueHost |
onCreatePrimaryActions
protected void onCreatePrimaryActions (ArrayObjectAdapter primaryActionsAdapter)
May be overridden to add primary actions to the adapter. Default implementation add
PlaybackControlsRow.PlayPauseAction
.
Parameters | |
---|---|
primaryActionsAdapter |
ArrayObjectAdapter : The adapter to add primary Action s.
|
onCreateRowPresenter
protected abstract PlaybackRowPresenter onCreateRowPresenter ()
Returns | |
---|---|
PlaybackRowPresenter |
onCreateSecondaryActions
protected void onCreateSecondaryActions (ArrayObjectAdapter secondaryActionsAdapter)
May be overridden to add secondary actions to the adapter.
Parameters | |
---|---|
secondaryActionsAdapter |
ArrayObjectAdapter : The adapter you need to add the Action s to.
|
onDetachedFromHost
protected void onDetachedFromHost ()
This method is called when current associated PlaybackGlueHost
is attached to a
different PlaybackGlue
or PlaybackGlueHost
is destroyed . Subclass may
override and call super.onDetachedFromHost() at last. A typical PlaybackGlue will release
resources (e.g. MediaPlayer or connection to playback service) in this method.
onHostStart
protected void onHostStart ()
This method is called when PlaybackGlueHost
is started. Subclass may override.
onHostStop
protected void onHostStop ()
This method is called when PlaybackGlueHost
is stopped. Subclass may override.
onMetadataChanged
protected void onMetadataChanged ()
Event when metadata changed
onPlayCompleted
protected void onPlayCompleted ()
Event when play finishes, subclass may handling repeat mode here.
onPlayStateChanged
protected void onPlayStateChanged ()
Event when play state changed.
onPreparedStateChanged
protected void onPreparedStateChanged ()
Event when ready state for play changes.
onUpdateBufferedProgress
protected void onUpdateBufferedProgress ()
onUpdateDuration
protected void onUpdateDuration ()
onUpdateProgress
protected void onUpdateProgress ()