PlaybackBaseControlGlue
abstract class PlaybackBaseControlGlue<T : PlayerAdapter?> : PlaybackGlue, OnActionClickedListener, View.OnKeyListener
PlaybackBannerControlGlue |
A helper class for managing a |
PlaybackTransportControlGlue |
A helper class for managing a |
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 PlaybackControlsRowPlaybackRowPresenter 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 and / or onCreateSecondaryActions and respond to actions by overriding onActionClicked.
The subclass is responsible for implementing the "repeat mode" in onPlayCompleted.
| Parameters | |
|---|---|
<T : PlayerAdapter?> |
Type of |
Summary
Constants |
|
|---|---|
const Int |
The adapter key for the first custom control on the left side of the predefined primary controls. |
const Int |
ACTION_CUSTOM_RIGHT_FIRST = 4096The adapter key for the first custom control on the right side of the predefined primary controls. |
const Int |
ACTION_FAST_FORWARD = 128The adapter key for the fast forward control. |
const Int |
ACTION_PLAY_PAUSE = 64The adapter key for the play/pause control. |
const Int |
ACTION_REPEAT = 512The adapter key for the repeat control. |
const Int |
ACTION_REWIND = 32The adapter key for the rewind control. |
const Int |
ACTION_SHUFFLE = 1024The adapter key for the shuffle control. |
const Int |
ACTION_SKIP_TO_NEXT = 256The adapter key for the skip to next control. |
const Int |
The adapter key for the skip to previous control. |
Public constructors |
|---|
PlaybackBaseControlGlue(context: Context, impl: T!)Constructor for the glue. |
Public functions |
|
|---|---|
Drawable? |
getArt() |
Long |
|
PlaybackControlsRow? |
Returns the playback controls row managed by the glue layer. |
Long |
|
Long |
|
PlaybackRowPresenter? |
Returns the playback controls row Presenter managed by the glue layer. |
T! |
|
CharSequence? |
Return The media subtitle. |
Long |
Returns a bitmask of actions supported by the media player. |
CharSequence? |
getTitle()Returns the title of the media item. |
Boolean |
Returns true if the controls auto hides after a timeout when media is playing. |
Boolean |
Returns true if media is currently playing. |
Boolean |
Returns true when the media player is prepared to start media playback. |
Unit |
next()Goes to the next media item. |
abstract Unit |
onActionClicked(action: Action)Handles action clicks. |
abstract Boolean |
Handles key events and returns true if handled. |
Unit |
pause()Pauses the media player. |
Unit |
play()Starts the media player. |
Unit |
previous()Goes to the previous media item. |
Unit |
Seek media to a new position. |
Unit |
Sets the drawable representing cover image. |
Unit |
setControlsOverlayAutoHideEnabled(enable: Boolean)Sets the controls to auto hide after a timeout when media is playing. |
Unit |
setControlsRow(controlsRow: PlaybackControlsRow)Sets the controls row to be managed by the glue layer. |
Unit |
setPlaybackRowPresenter(presenter: PlaybackRowPresenter?)Sets the controls row Presenter to be managed by the glue layer. |
Unit |
setSubtitle(subtitle: CharSequence?)Sets the media subtitle. |
Unit |
setTitle(title: CharSequence?)Sets the media title. |
Protected functions |
|
|---|---|
java-static Unit |
notifyItemChanged(adapter: ArrayObjectAdapter, object: Any) |
Unit |
onAttachedToHost(host: PlaybackGlueHost)This method is called attached to associated |
Unit |
onCreatePrimaryActions(primaryActionsAdapter: ArrayObjectAdapter)May be overridden to add primary actions to the adapter. |
abstract PlaybackRowPresenter |
|
Unit |
onCreateSecondaryActions(secondaryActionsAdapter: ArrayObjectAdapter)May be overridden to add secondary actions to the adapter. |
Unit |
This method is called when current associated |
Unit |
This method is called when |
Unit |
This method is called when |
Unit |
Event when metadata changed |
Unit |
Event when play finishes, subclass may handling repeat mode here. |
Unit |
Event when play state changed. |
Unit |
Event when ready state for play changes. |
Unit |
|
Unit |
|
Unit |
Inherited functions |
||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Constants
ACTION_CUSTOM_LEFT_FIRST
const val ACTION_CUSTOM_LEFT_FIRST = 1: Int
The adapter key for the first custom control on the left side of the predefined primary controls.
ACTION_CUSTOM_RIGHT_FIRST
const val ACTION_CUSTOM_RIGHT_FIRST = 4096: Int
The adapter key for the first custom control on the right side of the predefined primary controls.
ACTION_FAST_FORWARD
const val ACTION_FAST_FORWARD = 128: Int
The adapter key for the fast forward control.
ACTION_PLAY_PAUSE
const val ACTION_PLAY_PAUSE = 64: Int
The adapter key for the play/pause control.
ACTION_REPEAT
const val ACTION_REPEAT = 512: Int
The adapter key for the repeat control.
ACTION_REWIND
const val ACTION_REWIND = 32: Int
The adapter key for the rewind control.
ACTION_SHUFFLE
const val ACTION_SHUFFLE = 1024: Int
The adapter key for the shuffle control.
ACTION_SKIP_TO_NEXT
const val ACTION_SKIP_TO_NEXT = 256: Int
The adapter key for the skip to next control.
ACTION_SKIP_TO_PREVIOUS
const val ACTION_SKIP_TO_PREVIOUS = 16: Int
The adapter key for the skip to previous control.
Public constructors
PlaybackBaseControlGlue
PlaybackBaseControlGlue(context: Context, impl: T!)
Constructor for the glue.
| Parameters | |
|---|---|
context: Context |
|
impl: T! |
Implementation to underlying media player. |
Public functions
getArt
fun getArt(): Drawable?
| Returns | |
|---|---|
Drawable? |
The drawable representing cover image. |
getBufferedPosition
fun getBufferedPosition(): Long
| Returns | |
|---|---|
Long |
The current buffered position of the media item in milliseconds. |
getControlsRow
fun getControlsRow(): PlaybackControlsRow?
Returns the playback controls row managed by the glue layer.
getCurrentPosition
fun getCurrentPosition(): Long
| Returns | |
|---|---|
Long |
The current position of the media item in milliseconds. |
getDuration
fun getDuration(): Long
| Returns | |
|---|---|
Long |
The duration of the media item in milliseconds. |
getPlaybackRowPresenter
fun getPlaybackRowPresenter(): PlaybackRowPresenter?
Returns the playback controls row Presenter managed by the glue layer.
getSupportedActions
fun getSupportedActions(): Long
Returns a bitmask of actions supported by the media player.
isControlsOverlayAutoHideEnabled
fun isControlsOverlayAutoHideEnabled(): Boolean
Returns true if the controls auto hides after a timeout when media is playing.
| See also | |
|---|---|
isControlsOverlayAutoHideEnabled |
isPrepared
fun isPrepared(): Boolean
Returns true when the media player is prepared to start media playback. When returning false, app may listen to onPreparedStateChanged event.
| Returns | |
|---|---|
Boolean |
True if prepared, false otherwise. |
onActionClicked
abstract fun onActionClicked(action: Action): Unit
Handles action clicks. A subclass may override this add support for additional actions.
onKey
abstract fun onKey(v: View!, keyCode: Int, event: KeyEvent!): Boolean
Handles key events and returns true if handled. A subclass may override this to provide additional support.
play
fun play(): Unit
Starts the media player. Does nothing if isPrepared is false. To wait isPrepared to be true before playing, use playWhenPrepared.
seekTo
fun seekTo(position: Long): Unit
Seek media to a new position.
| Parameters | |
|---|---|
position: Long |
New position. |
setArt
fun setArt(cover: Drawable?): Unit
Sets the drawable representing cover image. The drawable will be rendered by default description presenter in setDescriptionPresenter.
| Parameters | |
|---|---|
cover: Drawable? |
The drawable representing cover image. |
setControlsOverlayAutoHideEnabled
fun setControlsOverlayAutoHideEnabled(enable: Boolean): Unit
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. |
| See also | |
|---|---|
setControlsOverlayAutoHideEnabled |
setControlsRow
fun setControlsRow(controlsRow: PlaybackControlsRow): Unit
Sets the controls row to be managed by the glue layer. If getPrimaryActionsAdapter is not provided, a default ArrayObjectAdapter will be created and initialized in onCreatePrimaryActions. If getSecondaryActionsAdapter is not provided, a default ArrayObjectAdapter will be created and initialized in onCreateSecondaryActions. The primary actions and playback state related aspects of the row are updated by the glue.
setPlaybackRowPresenter
fun setPlaybackRowPresenter(presenter: PlaybackRowPresenter?): Unit
Sets the controls row Presenter to be managed by the glue layer.
setSubtitle
fun setSubtitle(subtitle: CharSequence?): Unit
Sets the media subtitle. The subtitle will be rendered by default description presenter setDescriptionPresenter.
| Parameters | |
|---|---|
subtitle: CharSequence? |
Subtitle to set. |
setTitle
fun setTitle(title: CharSequence?): Unit
Sets the media title. The title will be rendered by default description presenter setDescriptionPresenter.
Protected functions
notifyItemChanged
protected java-static fun notifyItemChanged(adapter: ArrayObjectAdapter, object: Any): Unit
onAttachedToHost
protected fun onAttachedToHost(host: PlaybackGlueHost): Unit
This method is called attached to associated PlaybackGlueHost. Subclass may override and call super.onAttachedToHost().
onCreatePrimaryActions
protected fun onCreatePrimaryActions(primaryActionsAdapter: ArrayObjectAdapter): Unit
May be overridden to add primary actions to the adapter. Default implementation add PlaybackControlsRow.PlayPauseAction.
| Parameters | |
|---|---|
primaryActionsAdapter: ArrayObjectAdapter |
The adapter to add primary |
onCreateRowPresenter
protected abstract fun onCreateRowPresenter(): PlaybackRowPresenter
onCreateSecondaryActions
protected fun onCreateSecondaryActions(secondaryActionsAdapter: ArrayObjectAdapter): Unit
May be overridden to add secondary actions to the adapter.
| Parameters | |
|---|---|
secondaryActionsAdapter: ArrayObjectAdapter |
The adapter you need to add the |
onDetachedFromHost
protected fun onDetachedFromHost(): Unit
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 fun onHostStart(): Unit
This method is called when PlaybackGlueHost is started. Subclass may override.
onHostStop
protected fun onHostStop(): Unit
This method is called when PlaybackGlueHost is stopped. Subclass may override.
onMetadataChanged
protected fun onMetadataChanged(): Unit
Event when metadata changed
onPlayCompleted
@CallSuper
protected fun onPlayCompleted(): Unit
Event when play finishes, subclass may handling repeat mode here.
onPlayStateChanged
@CallSuper
protected fun onPlayStateChanged(): Unit
Event when play state changed.
onPreparedStateChanged
@CallSuper
protected fun onPreparedStateChanged(): Unit
Event when ready state for play changes.