PlaybackBannerControlGlue


class PlaybackBannerControlGlue<T : PlayerAdapter?> : PlaybackBaseControlGlue


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.

Sample Code:
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 PlayerAdapter passed in constructor.

Summary

Constants

const Int

The adapter key for the first custom control on the left side of the predefined primary controls.

const Int

The adapter key for the first custom control on the right side of the predefined primary controls.

const Int

The adapter key for the fast forward control.

const Int

The adapter key for the play/pause control.

const Int

The adapter key for the rewind control.

const Int

The 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(
    context: Context,
    fastForwardSpeeds: IntArray,
    rewindSpeeds: IntArray,
    impl: T!
)

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

Handles action clicks.

Boolean
onKey(v: View!, keyCode: Int, event: KeyEvent!)

Handles key events and returns true if handled.

Unit

Pauses the media player.

Unit

Starts the media player.

Unit

Sets the controls row to be managed by the glue layer.

Protected functions

Unit

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

From androidx.leanback.media.PlaybackBaseControlGlue
const Int

The adapter key for the first custom control on the left side of the predefined primary controls.

const Int

The adapter key for the first custom control on the right side of the predefined primary controls.

const Int

The adapter key for the fast forward control.

const Int

The adapter key for the play/pause control.

const Int

The adapter key for the repeat control.

const Int

The adapter key for the rewind control.

const Int

The adapter key for the shuffle control.

const Int

The adapter key for the skip to next control.

const Int

The adapter key for the skip to previous control.

Inherited functions

From androidx.leanback.media.PlaybackBaseControlGlue
Drawable?
Long
PlaybackControlsRow?

Returns the playback controls row managed by the glue layer.

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?

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

Goes to the next media item.

java-static Unit
Unit

This method is called attached to associated PlaybackGlueHost.

Unit
onCreateSecondaryActions(secondaryActionsAdapter: ArrayObjectAdapter)

May be overridden to add secondary actions to the adapter.

Unit

This method is called when current associated PlaybackGlueHost is attached to a different PlaybackGlue or PlaybackGlueHost is destroyed .

Unit

This method is called when PlaybackGlueHost is started.

Unit

This method is called when PlaybackGlueHost is stopped.

Unit

Event when metadata changed

Unit

Event when ready state for play changes.

Unit
Unit
Unit
Unit

Goes to the previous media item.

Unit
seekTo(position: Long)

Seek media to a new position.

Unit
setArt(cover: Drawable?)

Sets the drawable representing cover image.

Unit

Sets the controls to auto hide after a timeout when media is playing.

Unit

Sets the controls row Presenter to be managed by the glue layer.

Unit

Sets the media subtitle.

Unit

Sets the media title.

From androidx.leanback.media.PlaybackGlue
Unit

Add a PlayerCallback.

Context

Returns the context.

PlaybackGlueHost?
(Mutable)List<PlaybackGlue.PlayerCallback!>?
Unit

This method is called when PlaybackGlueHost is paused.

Unit

This method is called when PlaybackGlueHost is resumed.

Unit

Starts play when isPrepared becomes true.

Unit

Remove a PlayerCallback.

Unit

This method is used to associate a PlaybackGlue with the PlaybackGlueHost which provides UI and optional SurfaceHolderGlueHost.

From android.view.View.OnKeyListener
abstract Boolean
onKey(p: View!, p1: Int, p2: KeyEvent!)

Constants

ACTION_CUSTOM_LEFT_FIRST

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
const val ACTION_FAST_FORWARD = 128: Int

The adapter key for the fast forward control.

ACTION_PLAY_PAUSE

Added in 1.1.0
const val ACTION_PLAY_PAUSE = 64: Int

The adapter key for the play/pause control.

ACTION_REWIND

Added in 1.1.0
const val ACTION_REWIND = 32: Int

The adapter key for the rewind control.

ACTION_SKIP_TO_NEXT

Added in 1.1.0
const val ACTION_SKIP_TO_NEXT = 256: Int

The adapter key for the skip to next control.

ACTION_SKIP_TO_PREVIOUS

Added in 1.1.0
const val ACTION_SKIP_TO_PREVIOUS = 16: Int

The adapter key for the skip to previous control.

PLAYBACK_SPEED_FAST_L0

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
const val PLAYBACK_SPEED_INVALID = -1: Int

Invalid playback speed.

PLAYBACK_SPEED_NORMAL

Added in 1.1.0
const val PLAYBACK_SPEED_NORMAL = 1: Int

Speed representing playback state that is playing normally.

PLAYBACK_SPEED_PAUSED

Added in 1.1.0
const val PLAYBACK_SPEED_PAUSED = 0: Int

Speed representing playback state that is paused.

Public constructors

PlaybackBannerControlGlue

Added in 1.1.0
PlaybackBannerControlGlue(context: Context, seekSpeeds: IntArray, impl: T!)

Constructor for the glue.

Parameters
context: Context
seekSpeeds: IntArray

The array of seek speeds for fast forward and rewind. The maximum length of the array is defined as NUMBER_OF_SEEK_SPEEDS.

impl: T!

Implementation to underlying media player.

PlaybackBannerControlGlue

Added in 1.1.0
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

Added in 1.1.0
fun getFastForwardSpeeds(): IntArray<Int>

Returns the fast forward speeds.

getRewindSpeeds

Added in 1.1.0
fun getRewindSpeeds(): IntArray<Int>

Returns the rewind speeds.

onActionClicked

Added in 1.2.0-alpha04
fun onActionClicked(action: Action): Unit

Handles action clicks. A subclass may override this add support for additional actions.

onKey

Added in 1.1.0
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.

pause

fun pause(): Unit

Pauses the media player.

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 Actions.

onCreateRowPresenter

Added in 1.2.0-alpha04
protected fun onCreateRowPresenter(): PlaybackRowPresenter

onPlayCompleted

protected fun onPlayCompleted(): Unit

Event when play finishes, subclass may handling repeat mode here.

onPlayStateChanged

protected fun onPlayStateChanged(): Unit

Event when play state changed.