PlaybackControlGlue
abstract class PlaybackControlGlue : PlaybackGlue, OnActionClickedListener, View.OnKeyListener
MediaControllerGlue |
This class is deprecated. Use |
A helper class for managing a PlaybackControlsRow and PlaybackGlueHost 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 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 MediaPlayerGlue 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.
You may override onCreateControlsRowAndPresenter which will create a PlaybackControlsRow and a PlaybackControlsRowPresenter. You may call setControlsRow and setPlaybackRowPresenter to customize your own row and presenter.
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 onCreatePrimaryActions. 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.
This helper implements a key event handler. If you pass a PlaybackGlueHost, it will configure its fragment to intercept all key events. Otherwise, you should set the glue object as key event handler to the ViewHolder when bound by your row presenter; see setOnKeyListener.
To update the controls row progress during playback, override enableProgressUpdating to manage the lifecycle of a periodic callback to updateProgress. getUpdatePeriod provides a recommended update period.
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_REWIND = 32The adapter key for the rewind 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. |
const Int |
The initial (level 0) fast forward playback speed. |
const Int |
The level 1 fast forward playback speed. |
const Int |
The level 2 fast forward playback speed. |
const Int |
The level 3 fast forward playback speed. |
const Int |
The level 4 fast forward playback speed. |
const Int |
Invalid playback speed. |
const Int |
Speed representing playback state that is playing normally. |
const Int |
Speed representing playback state that is paused. |
Public constructors |
|---|
PlaybackControlGlue(context: Context!, seekSpeeds: IntArray!)Constructor for the glue. |
PlaybackControlGlue(Constructor for the glue. |
Public functions |
|
|---|---|
Unit |
enableProgressUpdating(enable: Boolean)Override this to start/stop a runnable to call |
PlaybackControlsRow! |
Returns the playback controls row managed by the glue layer. |
PlaybackControlsRowPresenter! |
This function is deprecated. PlaybackControlGlue supports any PlaybackRowPresenter, use |
abstract Int |
Returns the current position of the media item in milliseconds. |
abstract Int |
Returns the current playback speed. |
IntArray<Int>! |
Returns the fast forward speeds. |
abstract Drawable! |
Returns a bitmap of the art for the media item. |
abstract Int |
Returns the duration of the media item in milliseconds. |
abstract CharSequence! |
Returns the subtitle of the media item. |
abstract CharSequence! |
Returns the title of the media item. |
PlaybackRowPresenter! |
Returns the playback row Presenter to be passed to |
IntArray<Int>! |
Returns the rewind speeds. |
abstract Long |
Returns a bitmask of actions supported by the media player. |
Int |
Returns the time period in milliseconds that should be used to update the progress. |
abstract Boolean |
Returns true if there is a valid media item. |
Boolean |
Returns true if controls are set to fade when media is playing. |
abstract Boolean |
Returns true if media is currently playing. |
Boolean |
Returns true if media is currently playing. |
Unit |
onActionClicked(action: Action!)Handles action clicks. |
Boolean |
Handles key events and returns true if handled. |
Unit |
play()Starts the media player. |
Unit |
Start playback at the given speed. |
Unit |
setControlsRow(controlsRow: PlaybackControlsRow!)Sets the controls row to be managed by the glue layer. |
Unit |
This function is deprecated. PlaybackControlGlue supports any PlaybackRowPresenter, use |
Unit |
setFadingEnabled(enable: Boolean)Sets the controls to fade after a timeout when media is playing. |
Unit |
setPlaybackRowPresenter(presenter: PlaybackRowPresenter!)Sets the controls row Presenter to be passed to |
Unit |
Updates the progress bar based on the current media playback position. |
Protected functions |
|
|---|---|
Unit |
onAttachedToHost(host: PlaybackGlueHost)This method is called attached to associated |
Unit |
Instantiating a |
Unit |
onCreatePrimaryActions(primaryActionsAdapter: SparseArrayObjectAdapter!)May be overridden to add primary actions to the adapter. |
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 |
Must be called appropriately by a subclass when the metadata state has changed. |
Unit |
Must be called appropriately by a subclass when the playback state has changed. |
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_REWIND
const val ACTION_REWIND = 32: Int
The adapter key for the rewind 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.
PLAYBACK_SPEED_FAST_L0
const val PLAYBACK_SPEED_FAST_L0 = 10: Int
The initial (level 0) fast forward playback speed. The negative of this value is for rewind at the same speed.
PLAYBACK_SPEED_FAST_L1
const val PLAYBACK_SPEED_FAST_L1 = 11: Int
The level 1 fast forward playback speed. The negative of this value is for rewind at the same speed.
PLAYBACK_SPEED_FAST_L2
const val PLAYBACK_SPEED_FAST_L2 = 12: Int
The level 2 fast forward playback speed. The negative of this value is for rewind at the same speed.
PLAYBACK_SPEED_FAST_L3
const val PLAYBACK_SPEED_FAST_L3 = 13: Int
The level 3 fast forward playback speed. The negative of this value is for rewind at the same speed.
PLAYBACK_SPEED_FAST_L4
const val PLAYBACK_SPEED_FAST_L4 = 14: Int
The level 4 fast forward playback speed. The negative of this value is for rewind at the same speed.
PLAYBACK_SPEED_INVALID
const val PLAYBACK_SPEED_INVALID = -1: Int
Invalid playback speed.
PLAYBACK_SPEED_NORMAL
const val PLAYBACK_SPEED_NORMAL = 1: Int
Speed representing playback state that is playing normally.
PLAYBACK_SPEED_PAUSED
const val PLAYBACK_SPEED_PAUSED = 0: Int
Speed representing playback state that is paused.
Public constructors
PlaybackControlGlue
PlaybackControlGlue(context: Context!, seekSpeeds: IntArray!)
Constructor for the glue.
PlaybackControlGlue
PlaybackControlGlue(
context: Context!,
fastForwardSpeeds: IntArray!,
rewindSpeeds: IntArray!
)
Constructor for the glue.
Public functions
enableProgressUpdating
fun enableProgressUpdating(enable: Boolean): Unit
Override this to start/stop a runnable to call updateProgress at an interval such as getUpdatePeriod.
getControlsRow
fun getControlsRow(): PlaybackControlsRow!
Returns the playback controls row managed by the glue layer.
fungetControlsRowPresenter(): PlaybackControlsRowPresenter!
Returns the playback controls row Presenter managed by the glue layer.
getCurrentPosition
abstract fun getCurrentPosition(): Int
Returns the current position of the media item in milliseconds.
getCurrentSpeedId
abstract fun getCurrentSpeedId(): Int
Returns the current playback speed. When playing normally, PLAYBACK_SPEED_NORMAL should be returned.
getFastForwardSpeeds
fun getFastForwardSpeeds(): IntArray<Int>!
Returns the fast forward speeds.
getMediaArt
abstract fun getMediaArt(): Drawable!
Returns a bitmap of the art for the media item.
getMediaDuration
abstract fun getMediaDuration(): Int
Returns the duration of the media item in milliseconds.
getMediaSubtitle
abstract fun getMediaSubtitle(): CharSequence!
Returns the subtitle of the media item.
getMediaTitle
abstract fun getMediaTitle(): CharSequence!
Returns the title of the media item.
getPlaybackRowPresenter
fun getPlaybackRowPresenter(): PlaybackRowPresenter!
Returns the playback row Presenter to be passed to PlaybackGlueHost in onAttachedToHost.
getSupportedActions
abstract fun getSupportedActions(): Long
Returns a bitmask of actions supported by the media player.
getUpdatePeriod
fun getUpdatePeriod(): Int
Returns the time period in milliseconds that should be used to update the progress. See updateProgress.
hasValidMedia
abstract fun hasValidMedia(): Boolean
Returns true if there is a valid media item.
isFadingEnabled
fun isFadingEnabled(): Boolean
Returns true if controls are set to fade when media is playing.
isMediaPlaying
abstract fun isMediaPlaying(): Boolean
Returns true if media is currently playing.
onActionClicked
fun onActionClicked(action: Action!): Unit
Handles action clicks. A subclass may override this add support for additional actions.
onKey
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.
play
fun play(speed: Int): Unit
Start playback at the given speed.
| Parameters | |
|---|---|
speed: Int |
The desired playback speed. For normal playback this will be |
setControlsRow
fun setControlsRow(controlsRow: PlaybackControlsRow!): Unit
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.
funsetControlsRowPresenter(presenter: PlaybackControlsRowPresenter!): Unit
Sets the controls row Presenter to be managed by the glue layer.
setFadingEnabled
fun setFadingEnabled(enable: Boolean): Unit
Sets the controls to fade after a timeout when media is playing.
setPlaybackRowPresenter
fun setPlaybackRowPresenter(presenter: PlaybackRowPresenter!): Unit
Sets the controls row Presenter to be passed to PlaybackGlueHost in onAttachedToHost.
updateProgress
fun updateProgress(): Unit
Updates the progress bar based on the current media playback position.
Protected functions
onAttachedToHost
protected fun onAttachedToHost(host: PlaybackGlueHost): Unit
This method is called attached to associated PlaybackGlueHost. Subclass may override and call super.onAttachedToHost().
onCreateControlsRowAndPresenter
protected fun onCreateControlsRowAndPresenter(): Unit
Instantiating a PlaybackControlsRow and corresponding PlaybackControlsRowPresenter. Subclass may override.
onCreatePrimaryActions
protected fun onCreatePrimaryActions(primaryActionsAdapter: SparseArrayObjectAdapter!): Unit
May be overridden to add primary actions to the adapter.
| Parameters | |
|---|---|
primaryActionsAdapter: SparseArrayObjectAdapter! |
The adapter to add primary |
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
Must be called appropriately by a subclass when the metadata state has changed.
onStateChanged
protected fun onStateChanged(): Unit
Must be called appropriately by a subclass when the playback state has changed. It updates the playback state displayed on the media player.