PlaybackTransportControlGlue
class PlaybackTransportControlGlue<T : PlayerAdapter?> : PlaybackBaseControlGlue
| kotlin.Any | |||
| ↳ | androidx.leanback.media.PlaybackGlue | ||
| ↳ | androidx.leanback.media.PlaybackBaseControlGlue | ||
| ↳ | androidx.leanback.media.PlaybackTransportControlGlue |
A helper 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 in that manages interaction between the leanback UI components PlaybackControlsRowPlaybackTransportRowPresenter and a functional PlayerAdapter which represents the underlying media player.
App must pass a PlayerAdapter in constructor for a specific implementation e.g. a MediaPlayerAdapter.
The glue has two actions bar: primary actions bar and secondary actions bar. App can provide additional actions by overriding onCreatePrimaryActions and / or onCreateSecondaryActions and respond to actions by override onActionClicked.
It's also subclass's responsibility to implement the "repeat mode" in onPlayCompleted.
Apps calls setSeekProvider to provide seek data. If the PlaybackGlueHost is instance of PlaybackSeekUi, the provider will be passed to PlaybackGlueHost to render thumb bitmaps.
public class MyVideoFragment extends VideoFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PlaybackTransportControlGlueplayerGlue = new PlaybackTransportControlGlue(getActivity(), new MediaPlayerAdapter(getActivity())); playerGlue.setHost(new VideoFragmentGlueHost(this)); playerGlue.setSubtitle("Leanback artist"); playerGlue.setTitle("Leanback team at work"); String uriPath = "android.resource://com.example.android.leanback/raw/video"; playerGlue.getPlayerAdapter().setDataSource(Uri.parse(uriPath)); playerGlue.playWhenPrepared(); } }
| Parameters | |
|---|---|
<T : PlayerAdapter?> |
Type of |
Summary
Public constructors |
|---|
PlaybackTransportControlGlue(context: Context!, impl: T!)Constructor for the glue. |
Public functions |
|
|---|---|
PlaybackSeekDataProvider! |
Get seek data provider used during user seeking. |
Boolean |
|
Unit |
onActionClicked(action: Action)Handles action clicks. |
Boolean |
Handles key events and returns true if handled. |
Unit |
setControlsRow(controlsRow: PlaybackControlsRow)Sets the controls row to be managed by the glue layer. |
Unit |
setSeekEnabled(seekEnabled: Boolean)Enable or disable seek when |
Unit |
setSeekProvider(seekProvider: PlaybackSeekDataProvider!)Set seek data provider used during user seeking. |
Protected functions |
|
|---|---|
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. |
PlaybackRowPresenter |
|
Unit |
This method is called when current associated |
Unit |
Event when play state changed. |
Unit |
Inherited Constants |
||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Public constructors
PlaybackTransportControlGlue
PlaybackTransportControlGlue(context: Context!, impl: T!)
Constructor for the glue.
| Parameters | |
|---|---|
context: Context! |
|
impl: T! |
Implementation to underlying media player. |
Public functions
getSeekProvider
fun getSeekProvider(): PlaybackSeekDataProvider!
Get seek data provider used during user seeking.
| Returns | |
|---|---|
PlaybackSeekDataProvider! |
Seek data provider used during user seeking. |
isSeekEnabled
fun isSeekEnabled(): Boolean
| Returns | |
|---|---|
Boolean |
True if seek is enabled without |
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.
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.
setSeekEnabled
fun setSeekEnabled(seekEnabled: Boolean): Unit
Enable or disable seek when getSeekProvider is null. When true, seekTo will be called during user seeking.
| Parameters | |
|---|---|
seekEnabled: Boolean |
True to enable seek, false otherwise |
setSeekProvider
fun setSeekProvider(seekProvider: PlaybackSeekDataProvider!): Unit
Set seek data provider used during user seeking.
| Parameters | |
|---|---|
seekProvider: PlaybackSeekDataProvider! |
Seek data provider used during user seeking. |
Protected functions
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 |
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.