PlaybackBannerControlGlue
public class PlaybackBannerControlGlue<T extends PlayerAdapter> extends PlaybackBaseControlGlue
| java.lang.Object | |||
| ↳ | 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 extends PlayerAdapter> |
Type of |
Summary
Constants |
|
|---|---|
static final int |
The adapter key for the first custom control on the left side of the predefined primary controls. |
static final int |
ACTION_CUSTOM_RIGHT_FIRST = 4096The adapter key for the first custom control on the right side of the predefined primary controls. |
static final int |
ACTION_FAST_FORWARD = 128The adapter key for the fast forward control. |
static final int |
ACTION_PLAY_PAUSE = 64The adapter key for the play/pause control. |
static final int |
ACTION_REWIND = 32The adapter key for the rewind control. |
static final int |
ACTION_SKIP_TO_NEXT = 256The adapter key for the skip to next control. |
static final int |
The adapter key for the skip to previous control. |
static final int |
The initial (level 0) fast forward playback speed. |
static final int |
The level 1 fast forward playback speed. |
static final int |
The level 2 fast forward playback speed. |
static final int |
The level 3 fast forward playback speed. |
static final int |
The level 4 fast forward playback speed. |
static final int |
Invalid playback speed. |
static final int |
Speed representing playback state that is playing normally. |
static final int |
Speed representing playback state that is paused. |
Public constructors |
|---|
PlaybackBannerControlGlue(Constructor for the glue. |
PlaybackBannerControlGlue(Constructor for the glue. |
Public methods |
|
|---|---|
long |
Gets current position of the player. |
@NonNull int[] |
Returns the fast forward speeds. |
@NonNull int[] |
Returns the rewind speeds. |
void |
onActionClicked(@NonNull Action action)Handles action clicks. |
boolean |
Handles key events and returns true if handled. |
void |
pause()Pauses the media player. |
void |
play()Starts the media player. |
void |
setControlsRow(@NonNull PlaybackControlsRow controlsRow)Sets the controls row to be managed by the glue layer. |
Protected methods |
|
|---|---|
void |
onCreatePrimaryActions(May be overridden to add primary actions to the adapter. |
@NonNull PlaybackRowPresenter |
|
void |
Event when play finishes, subclass may handling repeat mode here. |
void |
Event when play state changed. |
Inherited Constants |
||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constants
ACTION_CUSTOM_LEFT_FIRST
public static final int ACTION_CUSTOM_LEFT_FIRST = 1
The adapter key for the first custom control on the left side of the predefined primary controls.
ACTION_CUSTOM_RIGHT_FIRST
public static final int ACTION_CUSTOM_RIGHT_FIRST = 4096
The adapter key for the first custom control on the right side of the predefined primary controls.
ACTION_FAST_FORWARD
public static final int ACTION_FAST_FORWARD = 128
The adapter key for the fast forward control.
ACTION_PLAY_PAUSE
public static final int ACTION_PLAY_PAUSE = 64
The adapter key for the play/pause control.
ACTION_REWIND
public static final int ACTION_REWIND = 32
The adapter key for the rewind control.
ACTION_SKIP_TO_NEXT
public static final int ACTION_SKIP_TO_NEXT = 256
The adapter key for the skip to next control.
ACTION_SKIP_TO_PREVIOUS
public static final int ACTION_SKIP_TO_PREVIOUS = 16
The adapter key for the skip to previous control.
PLAYBACK_SPEED_FAST_L0
public static final int PLAYBACK_SPEED_FAST_L0 = 10
The initial (level 0) fast forward playback speed. The negative of this value is for rewind at the same speed.
PLAYBACK_SPEED_FAST_L1
public static final int PLAYBACK_SPEED_FAST_L1 = 11
The level 1 fast forward playback speed. The negative of this value is for rewind at the same speed.
PLAYBACK_SPEED_FAST_L2
public static final int PLAYBACK_SPEED_FAST_L2 = 12
The level 2 fast forward playback speed. The negative of this value is for rewind at the same speed.
PLAYBACK_SPEED_FAST_L3
public static final int PLAYBACK_SPEED_FAST_L3 = 13
The level 3 fast forward playback speed. The negative of this value is for rewind at the same speed.
PLAYBACK_SPEED_FAST_L4
public static final int PLAYBACK_SPEED_FAST_L4 = 14
The level 4 fast forward playback speed. The negative of this value is for rewind at the same speed.
PLAYBACK_SPEED_INVALID
public static final int PLAYBACK_SPEED_INVALID = -1
Invalid playback speed.
PLAYBACK_SPEED_NORMAL
public static final int PLAYBACK_SPEED_NORMAL = 1
Speed representing playback state that is playing normally.
PLAYBACK_SPEED_PAUSED
public static final int PLAYBACK_SPEED_PAUSED = 0
Speed representing playback state that is paused.
Public constructors
PlaybackBannerControlGlue
public PlaybackBannerControlGlue(
@NonNull Context context,
@NonNull int[] seekSpeeds,
T impl
)
Constructor for the glue.
PlaybackBannerControlGlue
public PlaybackBannerControlGlue(
@NonNull Context context,
@NonNull int[] fastForwardSpeeds,
@NonNull int[] rewindSpeeds,
T impl
)
Constructor for the glue.
| Parameters | |
|---|---|
@NonNull Context context |
|
@NonNull int[] fastForwardSpeeds |
The array of seek speeds for fast forward. The maximum length of the array is defined as NUMBER_OF_SEEK_SPEEDS. |
@NonNull int[] rewindSpeeds |
The array of seek speeds for rewind. The maximum length of the array is defined as NUMBER_OF_SEEK_SPEEDS. |
T impl |
Implementation to underlying media player. |
Public methods
getCurrentPosition
public long getCurrentPosition()
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
public @NonNull int[] getFastForwardSpeeds()
Returns the fast forward speeds.
onActionClicked
public void onActionClicked(@NonNull Action action)
Handles action clicks. A subclass may override this add support for additional actions.
onKey
public boolean onKey(View v, int keyCode, KeyEvent event)
Handles key events and returns true if handled. A subclass may override this to provide additional support.
play
public void play()
Starts the media player. Does nothing if isPrepared is false. To wait isPrepared to be true before playing, use playWhenPrepared.
setControlsRow
public void setControlsRow(@NonNull PlaybackControlsRow controlsRow)
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 methods
onCreatePrimaryActions
protected void onCreatePrimaryActions(
@NonNull ArrayObjectAdapter primaryActionsAdapter
)
May be overridden to add primary actions to the adapter. Default implementation add PlaybackControlsRow.PlayPauseAction.
| Parameters | |
|---|---|
@NonNull ArrayObjectAdapter primaryActionsAdapter |
The adapter to add primary |
onPlayCompleted
protected void onPlayCompleted()
Event when play finishes, subclass may handling repeat mode here.