MediaControllerGlue

Added in 1.1.0
Deprecated in 1.1.0

public abstract class MediaControllerGlue extends PlaybackControlGlue


A helper class for implementing a glue layer for MediaControllerCompat.

Summary

Public constructors

MediaControllerGlue(
    Context context,
    int[] fastForwardSpeeds,
    int[] rewindSpeeds
)

Constructor for the glue.

Public methods

void

Attaches to the given media controller.

void

Detaches from the media controller.

int

Returns the current position of the media item in milliseconds.

int

Returns the current playback speed.

Drawable

Returns a bitmap of the art for the media item.

final MediaControllerCompat

Returns the media controller currently attached.

int

Returns the duration of the media item in milliseconds.

CharSequence

Returns the subtitle of the media item.

CharSequence

Returns the title of the media item.

long

Returns a bitmask of actions supported by the media player.

boolean

Returns true if there is a valid media item.

boolean

Returns true if media is currently playing.

void

Goes to the next media item.

void

Pauses the media player.

void
play(int speed)

Start playback at the given speed.

void

Goes to the previous media item.

Inherited Constants

From androidx.leanback.media.PlaybackControlGlue
static final int

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

static final int

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

static final int

The adapter key for the fast forward control.

static final int

The adapter key for the play/pause control.

static final int

The adapter key for the rewind control.

static final int

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

Inherited methods

From androidx.leanback.widget.OnActionClickedListener
abstract void

Callback fired when the host fragment receives an action.

From androidx.leanback.media.PlaybackControlGlue
void
enableProgressUpdating(boolean enable)

Override this to start/stop a runnable to call updateProgress at an interval such as getUpdatePeriod.

PlaybackControlsRow

Returns the playback controls row managed by the glue layer.

PlaybackControlsRowPresenter

This method is deprecated.

PlaybackControlGlue supports any PlaybackRowPresenter, use getPlaybackRowPresenter.

int[]

Returns the fast forward speeds.

PlaybackRowPresenter

Returns the playback row Presenter to be passed to PlaybackGlueHost in onAttachedToHost.

int[]

Returns the rewind speeds.

int

Returns the time period in milliseconds that should be used to update the progress.

boolean

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

boolean

Returns true if media is currently playing.

void

Handles action clicks.

void

This method is called attached to associated PlaybackGlueHost.

void

Instantiating a PlaybackControlsRow and corresponding PlaybackControlsRowPresenter.

void

May be overridden to add primary actions to the adapter.

void

May be overridden to add secondary actions to the adapter.

void

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

void

This method is called when PlaybackGlueHost is started.

void

This method is called when PlaybackGlueHost is stopped.

boolean
onKey(View v, int keyCode, KeyEvent event)

Handles key events and returns true if handled.

void

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

void

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

final void

Starts the media player.

void

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

void

This method is deprecated.

PlaybackControlGlue supports any PlaybackRowPresenter, use setPlaybackRowPresenter.

void
setFadingEnabled(boolean enable)

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

void

Sets the controls row Presenter to be passed to PlaybackGlueHost in onAttachedToHost.

void

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

From androidx.leanback.media.PlaybackGlue
void

Add a PlayerCallback.

@NonNull Context

Returns the context.

@Nullable PlaybackGlueHost
@Nullable List<PlaybackGlue.PlayerCallback>
boolean

Returns true when the media player is prepared to start media playback.

void

This method is called when PlaybackGlueHost is paused.

void

This method is called when PlaybackGlueHost is resumed.

void

Starts play when isPrepared becomes true.

void

Remove a PlayerCallback.

final void

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(View p, int p1, KeyEvent p2)

Public constructors

MediaControllerGlue

Added in 1.1.0
Deprecated in 1.1.0
public MediaControllerGlue(
    Context context,
    int[] fastForwardSpeeds,
    int[] rewindSpeeds
)

Constructor for the glue.

Parameters
Context context
int[] fastForwardSpeeds

Array of seek speeds for fast forward.

int[] rewindSpeeds

Array of seek speeds for rewind.

Public methods

attachToMediaController

Added in 1.1.0
Deprecated in 1.1.0
public void attachToMediaController(MediaControllerCompat mediaController)

Attaches to the given media controller.

detach

Added in 1.1.0
Deprecated in 1.1.0
public void detach()

Detaches from the media controller. Must be called when the object is no longer needed.

getCurrentPosition

Added in 1.2.0-alpha04
Deprecated in 1.2.0-alpha04
public int getCurrentPosition()

Returns the current position of the media item in milliseconds.

getCurrentSpeedId

Added in 1.2.0-alpha04
Deprecated in 1.2.0-alpha04
public int getCurrentSpeedId()

Returns the current playback speed. When playing normally, PLAYBACK_SPEED_NORMAL should be returned.

getMediaArt

Added in 1.2.0-alpha04
Deprecated in 1.2.0-alpha04
public Drawable getMediaArt()

Returns a bitmap of the art for the media item.

getMediaController

Added in 1.1.0
Deprecated in 1.1.0
public final MediaControllerCompat getMediaController()

Returns the media controller currently attached.

getMediaDuration

Added in 1.2.0-alpha04
Deprecated in 1.2.0-alpha04
public int getMediaDuration()

Returns the duration of the media item in milliseconds.

getMediaSubtitle

Added in 1.2.0-alpha04
Deprecated in 1.2.0-alpha04
public CharSequence getMediaSubtitle()

Returns the subtitle of the media item.

getMediaTitle

Added in 1.2.0-alpha04
Deprecated in 1.2.0-alpha04
public CharSequence getMediaTitle()

Returns the title of the media item.

getSupportedActions

Added in 1.2.0-alpha04
Deprecated in 1.2.0-alpha04
public long getSupportedActions()

Returns a bitmask of actions supported by the media player.

hasValidMedia

Added in 1.2.0-alpha04
Deprecated in 1.2.0-alpha04
public boolean hasValidMedia()

Returns true if there is a valid media item.

isMediaPlaying

Added in 1.2.0-alpha04
Deprecated in 1.2.0-alpha04
public boolean isMediaPlaying()

Returns true if media is currently playing.

next

public void next()

Goes to the next media item. This method is optional.

pause

public void pause()

Pauses the media player.

play

public void play(int speed)

Start playback at the given speed.

Parameters
int speed

The desired playback speed. For normal playback this will be PLAYBACK_SPEED_NORMAL; higher positive values for fast forward, and negative values for rewind.

previous

public void previous()

Goes to the previous media item. This method is optional.