public class

UIMediaController

extends Object
implements SessionManagerListener<CastSession> RemoteMediaClient.Listener
java.lang.Object
   ↳ com.google.android.gms.cast.framework.media.uicontroller.UIMediaController

Class Overview

A UIMediaController lets you bind the state of Android UI components to the state of a remote CastSession. This class simplifies writing a sender UI with playback controls. To use this class, create an instance of this class, then call various bind methods to associate state of your Android UI components to a remote playback control, or the change of the remote playback state or metadata.

Summary

Public Constructors
UIMediaController(Activity activity)
Constructs an instance of UIMediaController that will be used to bind UI elements of an activity.
Public Methods
void bindImageViewToImageOfCurrentItem(ImageView view, int imageType, int placeHolderDrawableResId)
Binds an ImageView to the first image of the current item.
void bindImageViewToImageOfPreloadedItem(ImageView view, int imageType, int placeHolderDrawableResId)
Binds an ImageView to the first image of the preloaded item.
void bindImageViewToMuteToggle(ImageView view)
Binds an ImageView to mute and unmute the Cast receiver device volume.
void bindImageViewToPlayPauseToggle(ImageView view, Drawable playDrawable, Drawable pauseDrawable, Drawable stopDrawable, View loadingIndicator, boolean hideViewWhenLoading)
Binds an ImageView to toggle play / pause of the current item.
void bindProgressBar(ProgressBar view)
Binds a ProgressBar to the playback progress of the current item.
void bindProgressBar(ProgressBar view, long progressUpdateStepMs)
Binds a ProgressBar to the playback progress of the current item.
void bindSeekBar(SeekBar view, long progressUpdateStepMs)
Binds a SeekBar to control the playback position of the current item.
void bindSeekBar(SeekBar view)
Binds a SeekBar to control the playback position of the current item.
void bindTextViewToMetadataOfCurrentItem(TextView view, String key)
Binds a TextView to the metadata of the current item, keyed by key.
void bindTextViewToMetadataOfCurrentItem(TextView view, List<String> keysInPreference)
Binds a TextView to the metadata of the current item, keyed by a list of keys in the order of preferences.
void bindTextViewToMetadataOfPreloadedItem(TextView view, String key)
Binds an TextView to the metadata of the preloaded item, keyed by key.
void bindTextViewToMetadataOfPreloadedItem(TextView view, List<String> keysInPreference)
Binds an TextView to the metadata of the preloaded item, keyed by a list of keys in the order of preferences.
void bindTextViewToStreamDuration(TextView view)
Binds a TextView to the playback duration of the current item.
void bindTextViewToStreamPosition(TextView view, boolean updateWhileScrubbing)
Binds a TextView to the playback position of the current item.
void bindTextViewToStreamPosition(TextView view, boolean updateWhileScrubbing, long progressUpdateStepMs)
Binds a TextView to the playback position of the current item.
void bindViewToClosedCaption(View view)
Binds a View to launching the TracksChooserDialogFragment when clicked.
void bindViewToForward(View view, long skipStepMs)
Binds a View to skip forward playback of the current item skipStepMs milliseconds.
void bindViewToLaunchExpandedController(View view)
Binds a View to launching the expanded controller Activity specified by the name in getExpandedControllerActivityClassName().
void bindViewToLoadingIndicator(View view)
Binds a View's visibility state to VISIBLE only when the remote receiver is either buffering, or loading the next item.
void bindViewToRewind(View view, long skipStepMs)
Binds a View to rewind playback of the current item skipStepMs milliseconds.
void bindViewToSkipNext(View view, int invisibleState)
Binds a View to skip to the next item in the queue.
void bindViewToSkipPrev(View view, int invisibleState)
Binds a View to skip to the previous item in the queue.
void bindViewVisibilityToMediaSession(View view, int invisibleState)
Binds a View's visibility state to the availability of a Cast media session.
void bindViewVisibilityToPreloadingEvent(View view, int invisibleState)
Binds a View's visibility state to the availability of a preloaded item.
void dispose()
Disposes this instance.
RemoteMediaClient getRemoteMediaClient()
Returns the managed RemoteMediaClient of the current active CastSession.
boolean isActive()
Returns true if there is an active connected Cast Session.
void onMetadataUpdated()
Called when updated media metadata is received.
void onPreloadStatusUpdated()
Called when updated player queue preload status information is received, for example, the next item to play has been preloaded.
void onQueueStatusUpdated()
Called when updated player queue status information is received.
void onSendingRemoteMediaRequest()
Called when there is an out going request to the receiver.
void onSessionEnded(CastSession session, int error)
void onSessionEnding(CastSession session)
void onSessionResumeFailed(CastSession session, int error)
void onSessionResumed(CastSession session, boolean wasSuspended)
void onSessionResuming(CastSession session, String sessionId)
void onSessionStartFailed(CastSession session, int error)
void onSessionStarted(CastSession session, String sessionId)
void onSessionStarting(CastSession session)
void onSessionSuspended(CastSession session, int reason)
void onStatusUpdated()
Called when updated player status information is received.
void setPostRemoteMediaClientListener(RemoteMediaClient.Listener listener)
Sets a RemoteMediaClient.Listener that will be called after all the other registered listeners in the UIMediaController instance are invoked.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.android.gms.cast.framework.SessionManagerListener
From interface com.google.android.gms.cast.framework.media.RemoteMediaClient.Listener

Public Constructors

public UIMediaController (Activity activity)

Constructs an instance of UIMediaController that will be used to bind UI elements of an activity.

Public Methods

public void bindImageViewToImageOfCurrentItem (ImageView view, int imageType, int placeHolderDrawableResId)

Binds an ImageView to the first image of the current item. If the current item doesn't contain any image or the SDK fails to fetch the Bitmap for the image, imagePlaceHolder will be used instead.

Parameters
view The View to bind.
placeHolderDrawableResId The resource ID of a Drawable used as a placeholder if no image is available from the current item.

public void bindImageViewToImageOfPreloadedItem (ImageView view, int imageType, int placeHolderDrawableResId)

Binds an ImageView to the first image of the preloaded item. If the current item doesn't contain any image or the SDK fails to fetch the Bitmap for the image, imagePlaceHolder will be used instead.

Parameters
view The View to bind.
placeHolderDrawableResId The resource ID of a Drawable used as a place holder if no image is available from the preloaded item.

public void bindImageViewToMuteToggle (ImageView view)

Binds an ImageView to mute and unmute the Cast receiver device volume. Tapping on view toggles its selection state. The selected state represents "mute", and the unselected state represents "unmute". Tapping on a "mute" button sends a mute request to the receiver, and tapping on an "unmute" button sends an unmute request. The bound view will also listen to onVolumeChanged() events to update its selection state.

Parameters
view The ImageView to bind.

public void bindImageViewToPlayPauseToggle (ImageView view, Drawable playDrawable, Drawable pauseDrawable, Drawable stopDrawable, View loadingIndicator, boolean hideViewWhenLoading)

Binds an ImageView to toggle play / pause of the current item.

Parameters
view The ImageView to bind.
playDrawable The Drawable to use when the state of the control is "play".
pauseDrawable The Drawable to use when the state of the control is "pause".
stopDrawable The Drawable to use when the state of the control is "stop live stream". If set to null, the SDK will display the pauseDrawable when a "stop live stream" icon is needed.
loadingIndicator A View that should be displayed to indicate that a remote request is ongoing.
hideViewWhenLoading true if visibility of imageView should be set to INVISIBLE when loading an item, false if it should be set to VISIBLE when loading an item.

public void bindProgressBar (ProgressBar view)

Binds a ProgressBar to the playback progress of the current item. Progress will be updated once per second. If no item is loaded the progress of the ProgressBar will be set to zero.

Parameters
view The ProgressBar to bind.

public void bindProgressBar (ProgressBar view, long progressUpdateStepMs)

Binds a ProgressBar to the playback progress of the current item. Progress will be updated once per progressUpdateStepMs milliseconds. If no item is loaded the progress of the ProgressBar will be set to zero.

Parameters
view The ProgressBar to bind.
progressUpdateStepMs The interval between each update of the progress, in milliseconds.

public void bindSeekBar (SeekBar view, long progressUpdateStepMs)

Binds a SeekBar to control the playback position of the current item. Progress will be updated once per progressUpdateStepMs milliseconds. If no item is loaded the progress of the ProgressBar will be set to zero.

Parameters
view The SeekBar to bind.
progressUpdateStepMs The interval between each update of the progress, in milliseconds.

public void bindSeekBar (SeekBar view)

Binds a SeekBar to control the playback position of the current item. Progress will be updated once per second. If no item is loaded the progress of the ProgressBar will be set to zero.

Parameters
view The SeekBar to bind.

public void bindTextViewToMetadataOfCurrentItem (TextView view, String key)

Binds a TextView to the metadata of the current item, keyed by key. If metadata for key is unavailable, the TextView will be left untouched.

Parameters
view The View to bind.
key The key of the metadata field to bind.

public void bindTextViewToMetadataOfCurrentItem (TextView view, List<String> keysInPreference)

Binds a TextView to the metadata of the current item, keyed by a list of keys in the order of preferences.

Parameters
view The View to bind.
keysInPreference The list of keys in the order of preference.

public void bindTextViewToMetadataOfPreloadedItem (TextView view, String key)

Binds an TextView to the metadata of the preloaded item, keyed by key. If metadata for key is unavailable, the TextView will be left untouched.

Parameters
view The View to bind.
key The key of the metadata field to bind.

public void bindTextViewToMetadataOfPreloadedItem (TextView view, List<String> keysInPreference)

Binds an TextView to the metadata of the preloaded item, keyed by a list of keys in the order of preferences.

Parameters
view The View to bind.
keysInPreference The list of keys in the order of preference.

public void bindTextViewToStreamDuration (TextView view)

Binds a TextView to the playback duration of the current item. If no item is loaded the text will be set to "--:--";

Parameters
view The TextView to bind.

public void bindTextViewToStreamPosition (TextView view, boolean updateWhileScrubbing)

Binds a TextView to the playback position of the current item. Position will be updated once per second. If no item is loaded the text will be set to "--:--";

Parameters
view The TextView to bind.
updateWhileScrubbing If this is set to true, the the text in view will be updated to the position of a bound SeekBar while is is being scrubbed.

public void bindTextViewToStreamPosition (TextView view, boolean updateWhileScrubbing, long progressUpdateStepMs)

Binds a TextView to the playback position of the current item. Position will be updated once per progressUpdateStepMs milliseconds. If no item is loaded the text will be set to "--:--";

Parameters
view The TextView to bind.
updateWhileScrubbing If this is set to true, the the text in view will be updated to the position of a bound SeekBar while is is being scrubbed.
progressUpdateStepMs The interval between each update of the progress, in milliseconds.

public void bindViewToClosedCaption (View view)

Binds a View to launching the TracksChooserDialogFragment when clicked.

public void bindViewToForward (View view, long skipStepMs)

Binds a View to skip forward playback of the current item skipStepMs milliseconds.

Parameters
view The View to bind.
skipStepMs Time (in milliseconds) to skip forward.

public void bindViewToLaunchExpandedController (View view)

Binds a View to launching the expanded controller Activity specified by the name in getExpandedControllerActivityClassName().

public void bindViewToLoadingIndicator (View view)

Binds a View's visibility state to VISIBLE only when the remote receiver is either buffering, or loading the next item. Otherwise visibility of the View will be set to GONE.

Parameters
view The View to bind.

public void bindViewToRewind (View view, long skipStepMs)

Binds a View to rewind playback of the current item skipStepMs milliseconds.

Parameters
view The View to bind.
skipStepMs Time (in milliseconds) to rewind.

public void bindViewToSkipNext (View view, int invisibleState)

Binds a View to skip to the next item in the queue.

Parameters
view The View to bind.
invisibleState Either INVISIBLE or GONE. This parameter will be set as the visibility of view when there isn't a previous item in the queue.

public void bindViewToSkipPrev (View view, int invisibleState)

Binds a View to skip to the previous item in the queue.

Parameters
view The View to bind.
invisibleState Either INVISIBLE or GONE. This parameter will be set as the visibility of view when there isn't a previous item in the queue.

public void bindViewVisibilityToMediaSession (View view, int invisibleState)

Binds a View's visibility state to the availability of a Cast media session. View will be set to VISIBLE when there is a media session, and will be set to invisibleState when there isn't a media session.

Parameters
view The View to bind.
invisibleState Either INVISIBLE or GONE, which will be set as the visibility of view when there isn't a media session.

public void bindViewVisibilityToPreloadingEvent (View view, int invisibleState)

Binds a View's visibility state to the availability of a preloaded item. View will be set to VISIBLE when there is a preloaded item, and will be set to invisibleState when there isn't a preloaded item.

Parameters
view The View to bind.
invisibleState Either INVISIBLE or GONE, which will be set as the visibility of view when there isn't a preloaded item.

public void dispose ()

Disposes this instance. The UIMediaController can not be reused after this method is called.

public RemoteMediaClient getRemoteMediaClient ()

Returns the managed RemoteMediaClient of the current active CastSession.

public boolean isActive ()

Returns true if there is an active connected Cast Session.

public void onMetadataUpdated ()

Called when updated media metadata is received.

public void onPreloadStatusUpdated ()

Called when updated player queue preload status information is received, for example, the next item to play has been preloaded. This gives the caller a chance to response to preloading related event, such as displaying what will be played next in the UI.

public void onQueueStatusUpdated ()

Called when updated player queue status information is received.

public void onSendingRemoteMediaRequest ()

Called when there is an out going request to the receiver. This gives the caller a chance to update state of the UI of the sender app, for example, disable some controls.

public void onSessionEnded (CastSession session, int error)

public void onSessionEnding (CastSession session)

public void onSessionResumeFailed (CastSession session, int error)

public void onSessionResumed (CastSession session, boolean wasSuspended)

public void onSessionResuming (CastSession session, String sessionId)

public void onSessionStartFailed (CastSession session, int error)

public void onSessionStarted (CastSession session, String sessionId)

public void onSessionStarting (CastSession session)

public void onSessionSuspended (CastSession session, int reason)

public void onStatusUpdated ()

Called when updated player status information is received.

public void setPostRemoteMediaClientListener (RemoteMediaClient.Listener listener)

Sets a RemoteMediaClient.Listener that will be called after all the other registered listeners in the UIMediaController instance are invoked. Also, the states of all the bound View instances are guaranteed to be updated before this listener is invoked.

This listener is useful if you want to modify the state of the bound View instances.