PlaybackGlue

abstract class PlaybackGlue
kotlin.Any
   ↳ androidx.leanback.media.PlaybackGlue

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:

In rare case if an PlaybackGlue wants to live outside fragment / activity life cycle, it may manages resource release by itself.

Summary

Nested classes
abstract

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

Public constructors
<init>(context: Context!)

Constructor.

Public methods
open Boolean

Returns true if media is currently playing.

open Unit

Starts play when #isPrepared() becomes true.

open Unit

Pauses the media player.

open PlaybackGlueHost!

open Unit

Goes to the previous media item.

open Boolean

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

open Context!

Returns the context.

Unit

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

open Unit

Starts the media player.

open Unit

Goes to the next media item.

open Unit

Remove a PlayerCallback.

open Unit

Add a PlayerCallback.

Protected methods
open Unit

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

open MutableList<PlaybackGlue.PlayerCallback!>!

open Unit

This method is called attached to associated PlaybackGlueHost.

open Unit

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

open Unit

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

open Unit

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

open Unit

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

Public constructors

<init>

PlaybackGlue(context: Context!)

Constructor.

Public methods

isPlaying

open fun isPlaying(): Boolean

Returns true if media is currently playing.

playWhenPrepared

open fun playWhenPrepared(): Unit

Starts play when #isPrepared() becomes true.

pause

open fun pause(): Unit

Pauses the media player.

getHost

open fun getHost(): PlaybackGlueHost!
Return
PlaybackGlueHost!: Associated PlaybackGlueHost or null if not attached to host.

previous

open fun previous(): Unit

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

isPrepared

open fun isPrepared(): Boolean

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

Return
Boolean: True if prepared, false otherwise.

getContext

open fun getContext(): Context!

Returns the context.

setHost

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.

play

open fun play(): Unit

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

next

open fun next(): Unit

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

removePlayerCallback

open fun removePlayerCallback(callback: PlaybackGlue.PlayerCallback!): Unit

Remove a PlayerCallback.

Parameters
callback PlaybackGlue.PlayerCallback!: The callback to remove.

addPlayerCallback

open fun addPlayerCallback(playerCallback: PlaybackGlue.PlayerCallback!): Unit

Add a PlayerCallback.

Parameters
playerCallback PlaybackGlue.PlayerCallback!: The callback to add.

Protected methods

onHostStart

protected open fun onHostStart(): Unit

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

getPlayerCallbacks

protected open fun getPlayerCallbacks(): MutableList<PlaybackGlue.PlayerCallback!>!
Return
MutableList<PlaybackGlue.PlayerCallback!>!: A snapshot of list of PlayerCallbacks set on the Glue.

onAttachedToHost

protected open fun onAttachedToHost(host: PlaybackGlueHost!): Unit

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

onDetachedFromHost

protected open 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.

onHostResume

protected open fun onHostResume(): Unit

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

onHostStop

protected open fun onHostStop(): Unit

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

onHostPause

protected open fun onHostPause(): Unit

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