PlaybackBannerControlGlue
class PlaybackBannerControlGlue<T : PlayerAdapter?> : PlaybackBaseControlGlue
| kotlin.Any | |||
| ↳ | androidx.leanback.media.PlaybackGlue | ||
| ↳ | androidx.leanback.media.PlaybackBaseControlGlue | ||
| ↳ | androidx.leanback.media.PlaybackBannerControlGlue |
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 that manages interaction between the leanback UI components PlaybackControlsRowPlaybackControlsRowPresenter and a functional PlayerAdapter which represents the underlying media player.
Apps must pass a PlayerAdapter in the 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.
public class MyVideoFragment extends VideoFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PlaybackBannerControlGlueplayerGlue = new PlaybackBannerControlGlue(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
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 |
|---|
PlaybackBannerControlGlue(context: Context, seekSpeeds: IntArray, impl: T!)Constructor for the glue. |
PlaybackBannerControlGlue(Constructor for the glue. |
Public functions |
|
|---|---|
Long |
Gets current position of the player. |
IntArray<Int> |
Returns the fast forward speeds. |
IntArray<Int> |
Returns the rewind speeds. |
Unit |
onActionClicked(action: Action)Handles action clicks. |
Boolean |
Handles key events and returns true if handled. |
Unit |
pause()Pauses the media player. |
Unit |
play()Starts the media player. |
Unit |
setControlsRow(controlsRow: PlaybackControlsRow)Sets the controls row to be managed by the glue layer. |
Protected functions |
|
|---|---|
Unit |
onCreatePrimaryActions(primaryActionsAdapter: ArrayObjectAdapter)May be overridden to add primary actions to the adapter. |
PlaybackRowPresenter |
|
Unit |
Event when play finishes, subclass may handling repeat mode here. |
Unit |
Event when play state changed. |
Inherited Constants |
||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
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
PlaybackBannerControlGlue
PlaybackBannerControlGlue(context: Context, seekSpeeds: IntArray, impl: T!)
Constructor for the glue.
PlaybackBannerControlGlue
PlaybackBannerControlGlue(
context: Context,
fastForwardSpeeds: IntArray,
rewindSpeeds: IntArray,
impl: T!
)
Constructor for the glue.
| Parameters | |
|---|---|
context: Context |
|
fastForwardSpeeds: IntArray |
The array of seek speeds for fast forward. The maximum length of the array is defined as NUMBER_OF_SEEK_SPEEDS. |
rewindSpeeds: IntArray |
The array of seek speeds for rewind. The maximum length of the array is defined as NUMBER_OF_SEEK_SPEEDS. |
impl: T! |
Implementation to underlying media player. |
Public functions
getCurrentPosition
fun getCurrentPosition(): Long
Gets current position of the player. If the player is playing/paused, this method returns current position from PlayerAdapter. Otherwise, if the player is fastforwarding/rewinding, the method fake-pauses the PlayerAdapter and returns its own calculated position.
| Returns | |
|---|---|
Long |
Current position of the player. |
getFastForwardSpeeds
fun getFastForwardSpeeds(): IntArray<Int>
Returns the fast forward speeds.
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.
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.
Protected functions
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 |
onPlayCompleted
protected fun onPlayCompleted(): Unit
Event when play finishes, subclass may handling repeat mode here.