public abstract class PlaybackGlue
extends Object


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.

See also:


Nested classes

class PlaybackGlue.PlayerCallback

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

Public constructors

PlaybackGlue(Context context)


Public methods

void addPlayerCallback(PlaybackGlue.PlayerCallback playerCallback)

Add a PlayerCallback.

Context getContext()

Returns the context.

PlaybackGlueHost getHost()
boolean isPlaying()

Returns true if media is currently playing.

boolean isPrepared()

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

void next()

Goes to the next media item.

void pause()

Pauses the media player.

void play()

Starts the media player.

void playWhenPrepared()

Starts play when isPrepared() becomes true.

void previous()

Goes to the previous media item.

void removePlayerCallback(PlaybackGlue.PlayerCallback callback)

Remove a PlayerCallback.

final void setHost(PlaybackGlueHost host)

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

Protected methods

List<PlaybackGlue.PlayerCallback> getPlayerCallbacks()
void onAttachedToHost(PlaybackGlueHost host)

This method is called attached to associated PlaybackGlueHost.

void onDetachedFromHost()

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

void onHostPause()

This method is called when PlaybackGlueHost is paused.