PlaybackGlue


public abstract class PlaybackGlue

Known direct subclasses
PlaybackBaseControlGlue

A base abstract class for managing a PlaybackControlsRow being displayed in PlaybackGlueHost.

PlaybackControlGlue

A helper class for managing a PlaybackControlsRow and 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.

Known indirect subclasses
MediaControllerGlue

This class is deprecated.

Use MediaControllerAdapter with PlaybackTransportControlGlue or PlaybackBannerControlGlue.

PlaybackBannerControlGlue

A helper class for managing a PlaybackControlsRow being displayed in PlaybackGlueHost.

PlaybackTransportControlGlue

A helper class for managing a PlaybackControlsRow being displayed in PlaybackGlueHost, it supports standard playback control actions play/pause, and skip next/previous.


Base class for abstraction of media play/pause feature. A subclass of PlaybackGlue will contain implementation of Media Player or a connection to playback Service. App initializes PlaybackGlue subclass, associated it with a PlaybackGlueHost. PlaybackGlueHost is typically implemented by a Fragment or an Activity, it provides the environment to render UI for PlaybackGlue object, it optionally provides SurfaceHolder via SurfaceHolderGlueHost to render video. A typical PlaybackGlue should release resources (e.g. MediaPlayer or connection to playback Service) in onDetachedFromHost. onDetachedFromHost is called in two cases:

  • app manually change it using setHost call
  • When host (fragment or activity) is destroyed
In rare case if an PlaybackGlue wants to live outside fragment / activity life cycle, it may manages resource release by itself.
See also
PlaybackGlueHost

Summary

Nested types

public abstract class PlaybackGlue.PlayerCallback

Interface to allow clients to take action once the video is ready to play and start stop.

Public constructors

Constructor.

Public methods

void

Add a PlayerCallback.

@NonNull Context

Returns the context.

@Nullable PlaybackGlueHost
boolean

Returns true if media is currently playing.

boolean

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

void

Goes to the next media item.

void

Pauses the media player.

void

Starts the media player.

void

Starts play when isPrepared becomes true.

void

Goes to the previous media item.

void

Remove a PlayerCallback.

final void

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

Protected methods

@Nullable List<PlaybackGlue.PlayerCallback>
void

This method is called attached to associated PlaybackGlueHost.

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

void

This method is called when PlaybackGlueHost is resumed.

void

This method is called when PlaybackGlueHost is started.

void

This method is called when PlaybackGlueHost is stopped.

Public constructors

PlaybackGlue

Added in 1.1.0
public PlaybackGlue(@NonNull Context context)

Constructor.

Public methods

addPlayerCallback

Added in 1.1.0
public void addPlayerCallback(@NonNull PlaybackGlue.PlayerCallback playerCallback)

Add a PlayerCallback.

Parameters
@NonNull PlaybackGlue.PlayerCallback playerCallback

The callback to add.

getContext

Added in 1.1.0
public @NonNull Context getContext()

Returns the context.

getHost

Added in 1.1.0
public @Nullable PlaybackGlueHost getHost()
Returns
@Nullable PlaybackGlueHost

Associated PlaybackGlueHost or null if not attached to host.

isPlaying

Added in 1.1.0
public boolean isPlaying()

Returns true if media is currently playing.

isPrepared

Added in 1.1.0
public boolean isPrepared()

Returns true when the media player is prepared to start media playback. When returning false, app may listen to onPreparedStateChanged event.

Returns
boolean

True if prepared, false otherwise.

next

Added in 1.1.0
public void next()

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

pause

Added in 1.1.0
public void pause()

Pauses the media player.

play

Added in 1.1.0
public void play()

Starts the media player. Does nothing if isPrepared is false. To wait isPrepared to be true before playing, use playWhenPrepared.

playWhenPrepared

Added in 1.1.0
public void playWhenPrepared()

Starts play when isPrepared becomes true.

previous

Added in 1.1.0
public void previous()

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

removePlayerCallback

Added in 1.1.0
public void removePlayerCallback(@NonNull PlaybackGlue.PlayerCallback callback)

Remove a PlayerCallback.

Parameters
@NonNull PlaybackGlue.PlayerCallback callback

The callback to remove.

setHost

Added in 1.1.0
public final void setHost(@Nullable PlaybackGlueHost host)

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

Parameters
@Nullable PlaybackGlueHost host

The host for the PlaybackGlue. Set to null to detach from the host.

Protected methods

getPlayerCallbacks

Added in 1.1.0
protected @Nullable List<PlaybackGlue.PlayerCallbackgetPlayerCallbacks()
Returns
@Nullable List<PlaybackGlue.PlayerCallback>

A snapshot of list of PlayerCallbacks set on the Glue.

onAttachedToHost

Added in 1.1.0
@CallSuper
protected void onAttachedToHost(@NonNull PlaybackGlueHost host)

This method is called attached to associated PlaybackGlueHost. Subclass may override and call super.onAttachedToHost().

onDetachedFromHost

Added in 1.1.0
@CallSuper
protected void onDetachedFromHost()

This method is called when current associated PlaybackGlueHost is attached to a different PlaybackGlue or 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.

onHostPause

Added in 1.1.0
protected void onHostPause()

This method is called when PlaybackGlueHost is paused. Subclass may override.

onHostResume

Added in 1.1.0
protected void onHostResume()

This method is called when PlaybackGlueHost is resumed. Subclass may override.

onHostStart

Added in 1.1.0
protected void onHostStart()

This method is called when PlaybackGlueHost is started. Subclass may override.

onHostStop

Added in 1.1.0
protected void onHostStop()

This method is called when PlaybackGlueHost is stopped. Subclass may override.