# PlaybackControlGlue

Artifact: [androidx.leanback:leanback](https://developer.android.com/jetpack/androidx/releases/leanback) [View Source](https://cs.android.com/search?q=file:androidx/leanback/media/PlaybackControlGlue.java+class:androidx.leanback.media.PlaybackControlGlue) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

*** ** * ** ***


```
public abstract class PlaybackControlGlue extends PlaybackGlue implements OnActionClickedListener, View.OnKeyListener
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.leanback.media.PlaybackGlue](https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue) ||
|   | ↳ | [androidx.leanback.media.PlaybackControlGlue](https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue) |

Known direct subclasses [MediaControllerGlue](https://developer.android.com/reference/androidx/leanback/media/MediaControllerGlue)

|---|---|
| `https://developer.android.com/reference/androidx/leanback/media/MediaControllerGlue` | **This class is deprecated.** Use `https://developer.android.com/reference/androidx/leanback/media/MediaControllerAdapter` with `https://developer.android.com/reference/androidx/leanback/media/PlaybackTransportControlGlue` or `https://developer.android.com/reference/androidx/leanback/media/PlaybackBannerControlGlue`. <br /> |

*** ** * ** ***

A helper class for managing a `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow` and `https://developer.android.com/reference/androidx/leanback/media/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 `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onMetadataChanged()` and `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#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 `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onCreateControlsRowAndPresenter()` which will create a `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow` and a `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRowPresenter`. You may call `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#setControlsRow(androidx.leanback.widget.PlaybackControlsRow)` and `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#setPlaybackRowPresenter(androidx.leanback.widget.PlaybackRowPresenter)` to customize your own row and presenter.

The helper sets a `https://developer.android.com/reference/androidx/leanback/widget/SparseArrayObjectAdapter` on the controls row as the primary actions adapter, and adds actions to it. You can provide additional actions by overriding `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onCreatePrimaryActions(androidx.leanback.widget.SparseArrayObjectAdapter)`. 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 `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onActionClicked(androidx.leanback.widget.Action)`.

This helper implements a key event handler. If you pass a `https://developer.android.com/reference/androidx/leanback/media/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 `https://developer.android.com/reference/androidx/leanback/widget/RowPresenter.ViewHolder#setOnKeyListener(android.view.View.OnKeyListener)`.

To update the controls row progress during playback, override `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#enableProgressUpdating(boolean)` to manage the lifecycle of a periodic callback to `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#updateProgress()`. `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getUpdatePeriod()` provides a recommended update period.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#ACTION_CUSTOM_LEFT_FIRST() = 1` The adapter key for the first custom control on the left side of the predefined primary controls. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#ACTION_CUSTOM_RIGHT_FIRST() = 4096` The adapter key for the first custom control on the right side of the predefined primary controls. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#ACTION_FAST_FORWARD() = 128` The adapter key for the fast forward control. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#ACTION_PLAY_PAUSE() = 64` The adapter key for the play/pause control. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#ACTION_REWIND() = 32` The adapter key for the rewind control. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#ACTION_SKIP_TO_NEXT() = 256` The adapter key for the skip to next control. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#ACTION_SKIP_TO_PREVIOUS() = 16` The adapter key for the skip to previous control. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#PLAYBACK_SPEED_FAST_L0() = 10` The initial (level 0) fast forward playback speed. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#PLAYBACK_SPEED_FAST_L1() = 11` The level 1 fast forward playback speed. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#PLAYBACK_SPEED_FAST_L2() = 12` The level 2 fast forward playback speed. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#PLAYBACK_SPEED_FAST_L3() = 13` The level 3 fast forward playback speed. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#PLAYBACK_SPEED_FAST_L4() = 14` The level 4 fast forward playback speed. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#PLAYBACK_SPEED_INVALID() = -1` Invalid playback speed. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#PLAYBACK_SPEED_NORMAL() = 1` Speed representing playback state that is playing normally. |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#PLAYBACK_SPEED_PAUSED() = 0` Speed representing playback state that is paused. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#PlaybackControlGlue(android.content.Context,int[])(https://developer.android.com/reference/android/content/Context.html context, int[] seekSpeeds)` Constructor for the glue. |
| `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#PlaybackControlGlue(android.content.Context,int[],int[])( https://developer.android.com/reference/android/content/Context.html context, int[] fastForwardSpeeds, int[] rewindSpeeds )` Constructor for the glue. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#enableProgressUpdating(boolean)(boolean enable)` Override this to start/stop a runnable to call `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#updateProgress()` at an interval such as `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getUpdatePeriod()`. |
| `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getControlsRow()()` Returns the playback controls row managed by the glue layer. |
| `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRowPresenter` | `[getControlsRowPresenter](https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getControlsRowPresenter())()` **This method is deprecated.** PlaybackControlGlue supports any PlaybackRowPresenter, use `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getPlaybackRowPresenter()`. <br /> |
| `abstract int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getCurrentPosition()()` Returns the current position of the media item in milliseconds. |
| `abstract int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getCurrentSpeedId()()` Returns the current playback speed. |
| `int[]` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getFastForwardSpeeds()()` Returns the fast forward speeds. |
| `abstract https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getMediaArt()()` Returns a bitmap of the art for the media item. |
| `abstract int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getMediaDuration()()` Returns the duration of the media item in milliseconds. |
| `abstract https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getMediaSubtitle()()` Returns the subtitle of the media item. |
| `abstract https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getMediaTitle()()` Returns the title of the media item. |
| `https://developer.android.com/reference/androidx/leanback/widget/PlaybackRowPresenter` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getPlaybackRowPresenter()()` Returns the playback row Presenter to be passed to `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` in `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#onAttachedToHost(androidx.leanback.media.PlaybackGlueHost)`. |
| `int[]` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getRewindSpeeds()()` Returns the rewind speeds. |
| `abstract long` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getSupportedActions()()` Returns a bitmask of actions supported by the media player. |
| `int` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getUpdatePeriod()()` Returns the time period in milliseconds that should be used to update the progress. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#hasValidMedia()()` Returns true if there is a valid media item. |
| `boolean` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#isFadingEnabled()()` Returns true if controls are set to fade when media is playing. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#isMediaPlaying()()` Returns true if media is currently playing. |
| `boolean` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#isPlaying()()` Returns true if media is currently playing. |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onActionClicked(androidx.leanback.widget.Action)(https://developer.android.com/reference/androidx/leanback/widget/Action action)` Handles action clicks. |
| `boolean` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onKey(android.view.View,int,android.view.KeyEvent)(https://developer.android.com/reference/android/view/View.html v, int keyCode, https://developer.android.com/reference/android/view/KeyEvent.html event)` Handles key events and returns true if handled. |
| `final void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#play()()` Starts the media player. |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#play(int)(int speed)` Start playback at the given speed. |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#setControlsRow(androidx.leanback.widget.PlaybackControlsRow)(https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow controlsRow)` Sets the controls row to be managed by the glue layer. |
| `void` | `[setControlsRowPresenter](https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#setControlsRowPresenter(androidx.leanback.widget.PlaybackControlsRowPresenter))(https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRowPresenter presenter)` **This method is deprecated.** PlaybackControlGlue supports any PlaybackRowPresenter, use `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#setPlaybackRowPresenter(androidx.leanback.widget.PlaybackRowPresenter)`. <br /> |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#setFadingEnabled(boolean)(boolean enable)` Sets the controls to fade after a timeout when media is playing. |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#setPlaybackRowPresenter(androidx.leanback.widget.PlaybackRowPresenter)(https://developer.android.com/reference/androidx/leanback/widget/PlaybackRowPresenter presenter)` Sets the controls row Presenter to be passed to `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` in `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#onAttachedToHost(androidx.leanback.media.PlaybackGlueHost)`. |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#updateProgress()()` Updates the progress bar based on the current media playback position. |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onAttachedToHost(androidx.leanback.media.PlaybackGlueHost)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost host)` This method is called attached to associated `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost`. |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onCreateControlsRowAndPresenter()()` Instantiating a `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow` and corresponding `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRowPresenter`. |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onCreatePrimaryActions(androidx.leanback.widget.SparseArrayObjectAdapter)(https://developer.android.com/reference/androidx/leanback/widget/SparseArrayObjectAdapter primaryActionsAdapter)` May be overridden to add primary actions to the adapter. |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onCreateSecondaryActions(androidx.leanback.widget.ArrayObjectAdapter)(https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter secondaryActionsAdapter)` May be overridden to add secondary actions to the adapter. |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onDetachedFromHost()()` This method is called when current associated `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` is attached to a different `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue` or `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` is destroyed . |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onHostStart()()` This method is called when `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` is started. |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onHostStop()()` This method is called when `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` is stopped. |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onMetadataChanged()()` Must be called appropriately by a subclass when the metadata state has changed. |
| `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#onStateChanged()()` Must be called appropriately by a subclass when the playback state has changed. |

| ### Inherited methods |
|---|
| From [androidx.leanback.media.PlaybackGlue](https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue) |---|---| | `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#addPlayerCallback(androidx.leanback.media.PlaybackGlue.PlayerCallback)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue.PlayerCallback playerCallback)` Add a PlayerCallback. | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#getContext()()` Returns the context. | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#getHost()()` | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue.PlayerCallback>` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#getPlayerCallbacks()()` | | `boolean` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#isPrepared()()` Returns true when the media player is prepared to start media playback. | | `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#next()()` Goes to the next media item. | | `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#onHostPause()()` This method is called when `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` is paused. | | `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#onHostResume()()` This method is called when `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` is resumed. | | `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#pause()()` Pauses the media player. | | `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#playWhenPrepared()()` Starts play when `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#isPrepared()` becomes true. | | `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#previous()()` Goes to the previous media item. | | `void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#removePlayerCallback(androidx.leanback.media.PlaybackGlue.PlayerCallback)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue.PlayerCallback callback)` Remove a PlayerCallback. | | `final void` | `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#setHost(androidx.leanback.media.PlaybackGlueHost)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost host)` This method is used to associate a PlaybackGlue with the `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` which provides UI and optional `https://developer.android.com/reference/androidx/leanback/media/SurfaceHolderGlueHost`. | |

## Constants

### ACTION_CUSTOM_LEFT_FIRST

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
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

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
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

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public static final int ACTION_FAST_FORWARD = 128
```

The adapter key for the fast forward control.

### ACTION_PLAY_PAUSE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public static final int ACTION_PLAY_PAUSE = 64
```

The adapter key for the play/pause control.

### ACTION_REWIND

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public static final int ACTION_REWIND = 32
```

The adapter key for the rewind control.

### ACTION_SKIP_TO_NEXT

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public static final int ACTION_SKIP_TO_NEXT = 256
```

The adapter key for the skip to next control.

### ACTION_SKIP_TO_PREVIOUS

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public static final int ACTION_SKIP_TO_PREVIOUS = 16
```

The adapter key for the skip to previous control.

### PLAYBACK_SPEED_FAST_L0

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
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

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
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

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
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

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
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

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
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

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public static final int PLAYBACK_SPEED_INVALID = -1
```

Invalid playback speed.

### PLAYBACK_SPEED_NORMAL

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public static final int PLAYBACK_SPEED_NORMAL = 1
```

Speed representing playback state that is playing normally.

### PLAYBACK_SPEED_PAUSED

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public static final int PLAYBACK_SPEED_PAUSED = 0
```

Speed representing playback state that is paused.

## Public constructors

### PlaybackControlGlue

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public PlaybackControlGlue(Context context, int[] seekSpeeds)
```

Constructor for the glue.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` |   |
| `int[] seekSpeeds` | Array of seek speeds for fast forward and rewind. |

### PlaybackControlGlue

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public PlaybackControlGlue(
    Context context,
    int[] fastForwardSpeeds,
    int[] rewindSpeeds
)
```

Constructor for the glue.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` |   |
| `int[] fastForwardSpeeds` | Array of seek speeds for fast forward. |
| `int[] rewindSpeeds` | Array of seek speeds for rewind. |

## Public methods

### enableProgressUpdating

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void enableProgressUpdating(boolean enable)
```

Override this to start/stop a runnable to call `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#updateProgress()` at an interval such as `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getUpdatePeriod()`.

### getControlsRow

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public PlaybackControlsRow getControlsRow()
```

Returns the playback controls row managed by the glue layer.

### getControlsRowPresenter

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public PlaybackControlsRowPresenter [getControlsRowPresenter](https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getControlsRowPresenter())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> PlaybackControlGlue supports any PlaybackRowPresenter, use `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#getPlaybackRowPresenter()`.

Returns the playback controls row Presenter managed by the glue layer.

### getCurrentPosition

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public abstract int getCurrentPosition()
```

Returns the current position of the media item in milliseconds.

### getCurrentSpeedId

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public abstract int getCurrentSpeedId()
```

Returns the current playback speed. When playing normally, `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#PLAYBACK_SPEED_NORMAL()` should be returned.

### getFastForwardSpeeds

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public int[] getFastForwardSpeeds()
```

Returns the fast forward speeds.

### getMediaArt

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public abstract Drawable getMediaArt()
```

Returns a bitmap of the art for the media item.

### getMediaDuration

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public abstract int getMediaDuration()
```

Returns the duration of the media item in milliseconds.

### getMediaSubtitle

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public abstract CharSequence getMediaSubtitle()
```

Returns the subtitle of the media item.

### getMediaTitle

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public abstract CharSequence getMediaTitle()
```

Returns the title of the media item.

### getPlaybackRowPresenter

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public PlaybackRowPresenter getPlaybackRowPresenter()
```

Returns the playback row Presenter to be passed to `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` in `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#onAttachedToHost(androidx.leanback.media.PlaybackGlueHost)`.

### getRewindSpeeds

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public int[] getRewindSpeeds()
```

Returns the rewind speeds.

### getSupportedActions

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public abstract long getSupportedActions()
```

Returns a bitmask of actions supported by the media player.

### getUpdatePeriod

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public int getUpdatePeriod()
```

Returns the time period in milliseconds that should be used to update the progress. See `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#updateProgress()`.

### hasValidMedia

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public abstract boolean hasValidMedia()
```

Returns true if there is a valid media item.

### isFadingEnabled

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public boolean isFadingEnabled()
```

Returns true if controls are set to fade when media is playing.

### isMediaPlaying

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public abstract boolean isMediaPlaying()
```

Returns true if media is currently playing.

### isPlaying

```
public boolean isPlaying()
```

Returns true if media is currently playing.

### onActionClicked

```
public void onActionClicked(Action action)
```

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

### onKey

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
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 final void play()
```

Starts the media player. Does nothing if `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#isPrepared()` is false. To wait `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#isPrepared()` to be true before playing, use `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#playWhenPrepared()`.

### play

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void play(int speed)
```

Start playback at the given speed.

| Parameters |
|---|---|
| `int speed` | The desired playback speed. For normal playback this will be `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#PLAYBACK_SPEED_NORMAL()`; higher positive values for fast forward, and negative values for rewind. |

### setControlsRow

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void setControlsRow(PlaybackControlsRow controlsRow)
```

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.

### setControlsRowPresenter

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void [setControlsRowPresenter](https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#setControlsRowPresenter(androidx.leanback.widget.PlaybackControlsRowPresenter))(PlaybackControlsRowPresenter presenter)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> PlaybackControlGlue supports any PlaybackRowPresenter, use `https://developer.android.com/reference/androidx/leanback/media/PlaybackControlGlue#setPlaybackRowPresenter(androidx.leanback.widget.PlaybackRowPresenter)`.

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

### setFadingEnabled

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void setFadingEnabled(boolean enable)
```

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

### setPlaybackRowPresenter

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void setPlaybackRowPresenter(PlaybackRowPresenter presenter)
```

Sets the controls row Presenter to be passed to `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` in `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue#onAttachedToHost(androidx.leanback.media.PlaybackGlueHost)`.

### updateProgress

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void updateProgress()
```

Updates the progress bar based on the current media playback position.

## Protected methods

### onAttachedToHost

```
protected void onAttachedToHost(@NonNull PlaybackGlueHost host)
```

This method is called attached to associated `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost`. Subclass may override and call super.onAttachedToHost().

### onCreateControlsRowAndPresenter

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
protected void onCreateControlsRowAndPresenter()
```

Instantiating a `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow` and corresponding `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRowPresenter`. Subclass may override.

### onCreatePrimaryActions

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
protected void onCreatePrimaryActions(SparseArrayObjectAdapter primaryActionsAdapter)
```

May be overridden to add primary actions to the adapter.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/leanback/widget/SparseArrayObjectAdapter primaryActionsAdapter` | The adapter to add primary `https://developer.android.com/reference/androidx/leanback/widget/Action`s. |

### onCreateSecondaryActions

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
protected void onCreateSecondaryActions(ArrayObjectAdapter secondaryActionsAdapter)
```

May be overridden to add secondary actions to the adapter.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter secondaryActionsAdapter` | The adapter you need to add the `https://developer.android.com/reference/androidx/leanback/widget/Action`s to. |

### onDetachedFromHost

```
protected void onDetachedFromHost()
```

This method is called when current associated `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` is attached to a different `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlue` or `https://developer.android.com/reference/androidx/leanback/media/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 void onHostStart()
```

This method is called when `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` is started. Subclass may override.

### onHostStop

```
protected void onHostStop()
```

This method is called when `https://developer.android.com/reference/androidx/leanback/media/PlaybackGlueHost` is stopped. Subclass may override.

### onMetadataChanged

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
protected void onMetadataChanged()
```

Must be called appropriately by a subclass when the metadata state has changed.

### onStateChanged

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
protected void onStateChanged()
```

Must be called appropriately by a subclass when the playback state has changed. It updates the playback state displayed on the media player.