PlaybackGlue
public abstract class PlaybackGlue
PlaybackBaseControlGlue |
A base abstract class for managing a |
PlaybackControlGlue |
A helper class for managing a |
MediaControllerGlue |
This class is deprecated. Use |
PlaybackBannerControlGlue |
A helper class for managing a |
PlaybackTransportControlGlue |
A helper class for managing a |
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
setHostcall - When host (fragment or activity) is destroyed
| See also | |
|---|---|
PlaybackGlueHost |
Summary
Nested types |
|---|
public abstract class PlaybackGlue.PlayerCallbackInterface to allow clients to take action once the video is ready to play and start stop. |
Public constructors |
|---|
PlaybackGlue(@NonNull Context context)Constructor. |
Public methods |
|
|---|---|
void |
addPlayerCallback(@NonNull PlaybackGlue.PlayerCallback playerCallback)Add a PlayerCallback. |
@NonNull Context |
Returns the context. |
@Nullable PlaybackGlueHost |
getHost() |
boolean |
Returns true if media is currently playing. |
boolean |
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 |
Starts play when |
void |
previous()Goes to the previous media item. |
void |
Remove a PlayerCallback. |
final void |
setHost(@Nullable PlaybackGlueHost host)This method is used to associate a PlaybackGlue with the |
Protected methods |
|
|---|---|
@Nullable List<PlaybackGlue.PlayerCallback> |
|
void |
This method is called attached to associated |
void |
This method is called when current associated |
void |
This method is called when |
void |
This method is called when |
void |
This method is called when |
void |
This method is called when |
Public constructors
Public methods
addPlayerCallback
public void addPlayerCallback(@NonNull PlaybackGlue.PlayerCallback playerCallback)
Add a PlayerCallback.
| Parameters | |
|---|---|
@NonNull PlaybackGlue.PlayerCallback playerCallback |
The callback to add. |
getHost
public @Nullable PlaybackGlueHost getHost()
| Returns | |
|---|---|
@Nullable PlaybackGlueHost |
Associated |
isPrepared
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. |
play
public void play()
Starts the media player. Does nothing if isPrepared is false. To wait isPrepared to be true before playing, use playWhenPrepared.
playWhenPrepared
public void playWhenPrepared()
Starts play when isPrepared becomes true.
previous
public void previous()
Goes to the previous media item. This method is optional.
removePlayerCallback
public void removePlayerCallback(@NonNull PlaybackGlue.PlayerCallback callback)
Remove a PlayerCallback.
| Parameters | |
|---|---|
@NonNull PlaybackGlue.PlayerCallback callback |
The callback to remove. |
setHost
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
protected @Nullable List<PlaybackGlue.PlayerCallback> getPlayerCallbacks()
| Returns | |
|---|---|
@Nullable List<PlaybackGlue.PlayerCallback> |
A snapshot of list of PlayerCallbacks set on the Glue. |
onAttachedToHost
@CallSuper
protected void onAttachedToHost(@NonNull PlaybackGlueHost host)
This method is called attached to associated PlaybackGlueHost. Subclass may override and call super.onAttachedToHost().
onDetachedFromHost
@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
protected void onHostPause()
This method is called when PlaybackGlueHost is paused. Subclass may override.
onHostResume
protected void onHostResume()
This method is called when PlaybackGlueHost is resumed. Subclass may override.
onHostStart
protected void onHostStart()
This method is called when PlaybackGlueHost is started. Subclass may override.
onHostStop
protected void onHostStop()
This method is called when PlaybackGlueHost is stopped. Subclass may override.