PlaybackBaseControlGlue
abstract class PlaybackBaseControlGlue<T : PlayerAdapter!> : PlaybackGlue, OnActionClickedListener, OnKeyListener
kotlin.Any | ||
↳ | androidx.leanback.media.PlaybackGlue | |
↳ | androidx.leanback.media.PlaybackBaseControlGlue |
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
and / or #onCreateSecondaryActions
and respond to actions by overriding #onActionClicked(Action)
.
The subclass is responsible for implementing the "repeat mode" in #onPlayCompleted()
.
Summary
Constants | |
---|---|
static Int |
The adapter key for the first custom control on the left side of the predefined primary controls. |
static Int |
The adapter key for the first custom control on the right side of the predefined primary controls. |
static Int |
The adapter key for the fast forward control. |
static Int |
The adapter key for the play/pause control. |
static Int |
The adapter key for the repeat control. |
static Int |
The adapter key for the rewind control. |
static Int |
The adapter key for the shuffle control. |
static Int |
The adapter key for the skip to next control. |
static Int |
The adapter key for the skip to previous control. |
Public constructors | |
---|---|
Constructor for the glue. |
Public methods | |
---|---|
Long | |
open Unit |
previous() |
open Long | |
open Drawable! |
getArt() |
open Unit |
play() |
open PlaybackRowPresenter! |
Returns the playback controls row Presenter managed by the glue layer. |
open CharSequence! |
Return The media subtitle. |
open Unit |
setTitle(title: CharSequence!) Sets the media title. |
open CharSequence! |
getTitle() Returns the title of the media item. |
abstract Boolean |
Handles key events and returns true if handled. |
open Long |
Returns a bitmask of actions supported by the media player. |
Boolean | |
open Unit |
setControlsOverlayAutoHideEnabled(enable: Boolean) Sets the controls to auto hide after a timeout when media is playing. |
open Unit |
setControlsRow(controlsRow: PlaybackControlsRow!) Sets the controls row to be managed by the glue layer. |
open Unit |
Sets the drawable representing cover image. |
Long | |
abstract Unit |
onActionClicked(action: Action!) Handles action clicks. |
Unit |
Seek media to a new position. |
T | |
open Unit |
next() |
open Unit |
setPlaybackRowPresenter(presenter: PlaybackRowPresenter!) Sets the controls row Presenter to be managed by the glue layer. |
open Unit |
setSubtitle(subtitle: CharSequence!) Sets the media subtitle. |
Boolean | |
open Boolean |
Returns true if the controls auto hides after a timeout when media is playing. |
open Unit |
pause() |
open PlaybackControlsRow! |
Returns the playback controls row managed by the glue layer. |
Protected methods | |
---|---|
open Unit |
onCreateSecondaryActions(secondaryActionsAdapter: ArrayObjectAdapter!) May be overridden to add secondary actions to the adapter. |
open Unit | |
open Unit | |
open Unit |
onCreatePrimaryActions(primaryActionsAdapter: ArrayObjectAdapter!) May be overridden to add primary actions to the adapter. |
open Unit |
Event when ready state for play changes. |
open Unit | |
open Unit | |
open Unit |
Event when play finishes, subclass may handling repeat mode here. |
open Unit |
Event when play state changed. |
open Unit | |
open Unit |
Event when metadata changed |
open Unit | |
abstract PlaybackRowPresenter! | |
open Unit |
onAttachedToHost(host: PlaybackGlueHost!) |
open static Unit |
notifyItemChanged(adapter: ArrayObjectAdapter!, object: Any!) |
Inherited functions | |
---|---|
Constants
ACTION_CUSTOM_LEFT_FIRST
static val ACTION_CUSTOM_LEFT_FIRST: Int
The adapter key for the first custom control on the left side of the predefined primary controls.
Value: 1
ACTION_CUSTOM_RIGHT_FIRST
static val ACTION_CUSTOM_RIGHT_FIRST: Int
The adapter key for the first custom control on the right side of the predefined primary controls.
Value: 4096
ACTION_FAST_FORWARD
static val ACTION_FAST_FORWARD: Int
The adapter key for the fast forward control.
Value: 128
ACTION_PLAY_PAUSE
static val ACTION_PLAY_PAUSE: Int
The adapter key for the play/pause control.
Value: 64
ACTION_SKIP_TO_NEXT
static val ACTION_SKIP_TO_NEXT: Int
The adapter key for the skip to next control.
Value: 256
ACTION_SKIP_TO_PREVIOUS
static val ACTION_SKIP_TO_PREVIOUS: Int
The adapter key for the skip to previous control.
Value: 16
Public constructors
<init>
PlaybackBaseControlGlue(context: Context!, impl: T)
Constructor for the glue.
Parameters | |
---|---|
context |
Context!: |
impl |
Context!: Implementation to underlying media player. |
Public methods
previous
open fun previous(): Unit
getCurrentPosition
open fun getCurrentPosition(): Long
Return | |
---|---|
Long: The current position of the media item in milliseconds. |
play
open fun play(): Unit
getPlaybackRowPresenter
open fun getPlaybackRowPresenter(): PlaybackRowPresenter!
Returns the playback controls row Presenter managed by the glue layer.
setTitle
open fun setTitle(title: CharSequence!): Unit
Sets the media title. The title will be rendered by default description presenter PlaybackTransportRowPresenter#setDescriptionPresenter(Presenter)
.
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.
getSupportedActions
open fun getSupportedActions(): Long
Returns a bitmask of actions supported by the media player.
isPrepared
fun isPrepared(): Boolean
setControlsOverlayAutoHideEnabled
open 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. |
setControlsRow
open fun setControlsRow(controlsRow: PlaybackControlsRow!): Unit
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.
setArt
open fun setArt(cover: Drawable!): Unit
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. |
getBufferedPosition
fun getBufferedPosition(): Long
Return | |
---|---|
Long: The current buffered position of the media item in milliseconds. |
onActionClicked
abstract fun onActionClicked(action: Action!): Unit
Handles action clicks. A subclass may override this add support for additional actions.
seekTo
fun seekTo(position: Long): Unit
Seek media to a new position.
Parameters | |
---|---|
position |
Long: New position. |
getPlayerAdapter
fun getPlayerAdapter(): T
next
open fun next(): Unit
setPlaybackRowPresenter
open fun setPlaybackRowPresenter(presenter: PlaybackRowPresenter!): Unit
Sets the controls row Presenter to be managed by the glue layer.
setSubtitle
open fun setSubtitle(subtitle: CharSequence!): Unit
Sets the media subtitle. The subtitle will be rendered by default description presenter PlaybackTransportRowPresenter#setDescriptionPresenter(Presenter)
.
Parameters | |
---|---|
subtitle |
CharSequence!: Subtitle to set. |
isPlaying
fun isPlaying(): Boolean
isControlsOverlayAutoHideEnabled
open fun isControlsOverlayAutoHideEnabled(): Boolean
Returns true if the controls auto hides after a timeout when media is playing.
pause
open fun pause(): Unit
getControlsRow
open fun getControlsRow(): PlaybackControlsRow!
Returns the playback controls row managed by the glue layer.
Protected methods
onCreateSecondaryActions
protected open 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 Action s to. |
onHostStop
protected open fun onHostStop(): Unit
onHostStart
protected open fun onHostStart(): Unit
onCreatePrimaryActions
protected open 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 Action s. |
onPreparedStateChanged
protected open fun onPreparedStateChanged(): Unit
Event when ready state for play changes.
onDetachedFromHost
protected open fun onDetachedFromHost(): Unit
onUpdateBufferedProgress
protected open fun onUpdateBufferedProgress(): Unit
onPlayCompleted
protected open fun onPlayCompleted(): Unit
Event when play finishes, subclass may handling repeat mode here.
onUpdateDuration
protected open fun onUpdateDuration(): Unit
onUpdateProgress
protected open fun onUpdateProgress(): Unit
onCreateRowPresenter
protected abstract fun onCreateRowPresenter(): PlaybackRowPresenter!
onAttachedToHost
protected open fun onAttachedToHost(host: PlaybackGlueHost!): Unit
notifyItemChanged
protected open static fun notifyItemChanged(adapter: ArrayObjectAdapter!, object: Any!): Unit
Interfaces
Classes
- PlayerAdapter
- PlayerAdapter.Callback
- PlaybackTransportControlGlue
- PlaybackGlue
- PlaybackGlue.PlayerCallback
- PlaybackControlGlue
- MediaPlayerAdapter
- PlaybackBaseControlGlue
- PlaybackBannerControlGlue
- PlaybackGlueHost
- PlaybackGlueHost.HostCallback
- PlaybackGlueHost.PlayerCallback
- MediaControllerAdapter
- MediaControllerGlue