PlaybackGlue

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

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

Public constructors

Constructor.

Public functions

Unit

Add a PlayerCallback.

Context

Returns the context.

PlaybackGlueHost?
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.

Unit

Pauses the media player.

Unit

Starts the media player.

Unit

Starts play when isPrepared becomes true.

Unit

Goes to the previous media item.

Unit

Remove a PlayerCallback.

Unit

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

Protected functions

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

This method is called attached to associated PlaybackGlueHost.

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

Unit

This method is called when PlaybackGlueHost is resumed.

Unit

This method is called when PlaybackGlueHost is started.

Unit

This method is called when PlaybackGlueHost is stopped.

Public constructors

PlaybackGlue

Added in 1.1.0
PlaybackGlue(context: Context)

Constructor.

Public functions

addPlayerCallback

Added in 1.1.0
fun addPlayerCallback(playerCallback: PlaybackGlue.PlayerCallback): Unit

Add a PlayerCallback.

Parameters
playerCallback: PlaybackGlue.PlayerCallback

The callback to add.

getContext

Added in 1.1.0
fun getContext(): Context

Returns the context.

getHost

Added in 1.1.0
fun getHost(): PlaybackGlueHost?
Returns
PlaybackGlueHost?

Associated PlaybackGlueHost or null if not attached to host.

isPlaying

Added in 1.1.0
fun isPlaying(): Boolean

Returns true if media is currently playing.

isPrepared

Added in 1.1.0
fun isPrepared(): Boolean

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
fun next(): Unit

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

pause

Added in 1.1.0
fun pause(): Unit

Pauses the media player.

play

Added in 1.1.0
fun play(): Unit

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
fun playWhenPrepared(): Unit

Starts play when isPrepared becomes true.

previous

Added in 1.1.0
fun previous(): Unit

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

removePlayerCallback

Added in 1.1.0
fun removePlayerCallback(callback: PlaybackGlue.PlayerCallback): Unit

Remove a PlayerCallback.

Parameters
callback: PlaybackGlue.PlayerCallback

The callback to remove.

setHost

Added in 1.1.0
fun setHost(host: PlaybackGlueHost?): Unit

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

Parameters
host: PlaybackGlueHost?

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

Protected functions

getPlayerCallbacks

Added in 1.1.0
protected fun getPlayerCallbacks(): (Mutable)List<PlaybackGlue.PlayerCallback!>?
Returns
(Mutable)List<PlaybackGlue.PlayerCallback!>?

A snapshot of list of PlayerCallbacks set on the Glue.

onAttachedToHost

Added in 1.1.0
@CallSuper
protected fun onAttachedToHost(host: PlaybackGlueHost): Unit

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

onDetachedFromHost

Added in 1.1.0
@CallSuper
protected fun onDetachedFromHost(): Unit

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 fun onHostPause(): Unit

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

onHostResume

Added in 1.1.0
protected fun onHostResume(): Unit

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

onHostStart

Added in 1.1.0
protected fun onHostStart(): Unit

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

onHostStop

Added in 1.1.0
protected fun onHostStop(): Unit

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