UIMediaController

public classUIMediaControllerextendsObject
implements RemoteMediaClient.ListenerSessionManagerListener<CastSession>

A UIMediaControllerlets you bind the state of Android UI components to the state of a remoteCastSession. 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.

When aViewis bound to the UIMediaController,on the one hand, UIMediaControllerwill update its UI state according to theCastSession state, the remote playback state or metadata. On the other hand, if theViewis bound to a remote playback command (such as "SkipNext" button), UIMediaControllerwill also register relevant listeners to theViewso that when the user interacts with the control, the controller will perform the corresponding action.

Take bindViewToSkipNext(View, int)as an example. When aViewis bound to the UIMediaController, UIMediaControllerwill update the state of theViewbased on the status of theCastSession, such that it will only be enabled when theCastSession is connected and there is a next item in the queue. AView.OnClickListener will also be set on theViewsuch that when the Viewis clicked, the event will be forwarded to onSkipNextClicked(View),whose default behavior is to call RemoteMediaClient.queueNext(JSONObject)on theRemoteMediaClient:

protected void onSkipNextClicked(View view) {
RemoteMediaClient remoteMediaClient = getRemoteMediaClient();
if ((remoteMediaClient!= null) && remoteMediaClient.hasMediaSession()) {
remoteMediaClient.queueNext(null /* customData */);
}
}
If the app needs to perform custom behavior in addition to, or instead of, the default behavior for a given action, it can subclass UIMediaController and override the corresponding event-handling method. For example:
public class CustomUIMediaController extends UIMediaController {
// Omitting other methods.

@Override
protected void onSkipNextClicked(View view) {
doSomeCustomAction();
super.onSkipNextClicked(view); // Optional
}
}

Public Constructor Summary

UIMediaController(Activity activity)
Constructs an instance of UIMediaControllerthat will be used to bind UI elements of an activity.

Public Method Summary

void
bindImageViewToImageOfCurrentItem(ImageView view, int imageType, int placeHolderDrawableResId)
void
bindImageViewToImageOfCurrentItem(ImageView view, int imageType,View placeHolderView)
void
bindImageViewToImageOfCurrentItem(ImageView view,ImageHints imageHints, int placeHolderDrawableResId)
Binds anImageView to the first image of the current item.
void
bindImageViewToImageOfCurrentItem(ImageView view,ImageHints imageHints,View placeHolderView)
Binds anImageView to an image of the current item.
void
bindImageViewToImageOfPreloadedItem(ImageView view, int imageType, int placeHolderDrawableResId)
void
bindImageViewToImageOfPreloadedItem(ImageView view,ImageHints imageHints, int placeHolderDrawableResId)
Binds anImageView to the first image of the preloaded item.
void
bindImageViewToMuteToggle(ImageView view)
Binds anImageView to mute and unmute the Cast receiver device volume.
void
bindImageViewToPlayPauseToggle(ImageView view,Drawable playDrawable,Drawable pauseDrawable,Drawable stopDrawable,View loadingIndicator, boolean hideViewWhenLoading)
Binds anImageView to toggle play / pause of the current item.
void
bindProgressBar(ProgressBar view)
Binds aProgressBar to the playback progress of the current item.
void
bindProgressBar(ProgressBar view, long progressUpdateStepMs)
Binds aProgressBar to the playback progress of the current item.
void
bindSeekBar(CastSeekBar view)
Binds a CastSeekBarto control the playback position of the current item.
void
bindSeekBar(SeekBarview, long progressUpdateStepMs)
Binds aSeekBar to control the playback position of the current item.
void
bindSeekBar(CastSeekBar view, long progressUpdateStepMs)
Binds a CastSeekBarto control the playback position of the current item.
void
bindSeekBar(SeekBarview)
Binds aSeekBar to control the playback position of the current item.
void
bindTextViewToMetadataOfCurrentItem(TextView view,Stringkey)
Binds aTextView to the metadata of the current item, keyed bykey.
void
bindTextViewToMetadataOfCurrentItem(TextView view,List<String> keysInPreference)
Binds aTextView to the metadata of the current item, keyed by a list of keys in the order of preferences.
void
bindTextViewToMetadataOfPreloadedItem(TextView view,List<String> keysInPreference)
Binds anTextView to the metadata of the preloaded item, keyed by a list of keys in the order of preferences.
void
bindTextViewToMetadataOfPreloadedItem(TextView view,Stringkey)
Binds anTextView to the metadata of the preloaded item, keyed bykey.
void
bindTextViewToSmartSubtitle(TextView textView)
Binds aTextView to the most appropriate item inMediaMetadata for subtitle.
void
bindTextViewToStreamDuration(TextView view,View liveStreamIndicator)
Binds aTextView to the playback duration of the current item.
void
bindTextViewToStreamDuration(TextView view)
Binds aTextView to the playback duration of the current item.
void
bindTextViewToStreamPosition(TextView view, boolean updateWhileScrubbing)
Binds aTextView to the playback position of the current item.
void
bindTextViewToStreamPosition(TextView view, boolean updateWhileScrubbing, long progressUpdateStepMs)
Binds aTextView to the playback position of the current item.
void
bindViewToClosedCaption(Viewview)
Binds aViewto launching the TracksChooserDialogFragmentwhen clicked.
void
bindViewToForward(Viewview, long skipStepMs)
Binds aViewto skip forward playback of the current itemskipStepMsmilliseconds.
void
bindViewToLaunchExpandedController(Viewview)
Binds aViewto launching the expanded controllerActivity specified by the name in CastMediaOptions.getExpandedControllerActivityClassName().
void
bindViewToLoadingIndicator(Viewview)
Binds aView's visibility state toView.VISIBLE only when the remote receiver is either buffering, or loading the next item.
void
bindViewToRewind(Viewview, long skipStepMs)
Binds aViewto rewind playback of the current itemskipStepMsmilliseconds.
void
bindViewToSkipNext(Viewview, int invisibleState)
Binds aViewto skip to the next item in the queue.
void
bindViewToSkipPrev(Viewview, int invisibleState)
Binds aViewto skip to the previous item in the queue.
void
void
bindViewVisibilityToMediaSession(Viewview, int invisibleState)
Binds aView's visibility state to the availability of a Cast media session.
void
bindViewVisibilityToPreloadingEvent(Viewview, int invisibleState)
Binds aView's visibility state to the availability of a preloaded item.
void
dispose()
Disposes this instance.
RemoteMediaClient
getRemoteMediaClient()
Returns the managed RemoteMediaClientof the current activeCastSession.
boolean
isActive()
Returns true if there is an active connected Cast Session.
void
onAdBreakStatusUpdated()
Called when updated ad break status information is received.
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 outgoing request to the receiver.
void
onSessionEnded(CastSession session, int error)
void
void
onSessionResumeFailed(CastSession session, int error)
void
onSessionResumed(CastSession session, boolean wasSuspended)
void
void
onSessionStartFailed(CastSession session, int error)
void
void
void
onSessionSuspended(CastSession session, int reason)
void
onStatusUpdated()
Called when updated player status information is received.
void
setPostRemoteMediaClientListener(RemoteMediaClient.Listener listener)
Sets a RemoteMediaClient.Listenerthat will be called after all the other registered listeners in the UIMediaControllerinstance are invoked.

Protected Method Summary

void
onClosedCaptionClicked(Viewview)
The callback that is invoked when the user clicks on anView bound to this UIMediaControllerthrough bindViewToClosedCaption(View).
void
onForwardClicked(Viewview, long skipStepMs)
The callback that is invoked when the user clicks on anView bound to this UIMediaControllerthrough bindViewToForward(View, long).
void
onLaunchExpandedControllerClicked(Viewview)
The callback that is invoked when the user clicks on anView bound to this UIMediaControllerthrough bindViewToLaunchExpandedController(View).
void
onMuteToggleClicked(ImageView view)
The callback that is invoked when the user clicks on anImageView bound to this UIMediaControllerthrough bindImageViewToMuteToggle(ImageView).
void
void
onRewindClicked(Viewview, long skipStepMs)
The callback that is invoked when the user clicks on anView bound to this UIMediaControllerthrough bindViewToRewind(View, long).
void
onSeekBarProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
The callback that is invoked on progress change of aSeekBar bound to this UIMediaControllerthrough bindSeekBar(SeekBar).
void
onSeekBarStartTrackingTouch(SeekBar seekBar)
The callback that is invoked when the user starts a touch gesture on a SeekBar bound to this UIMediaControllerthrough bindSeekBar(SeekBar).
void
onSeekBarStopTrackingTouch(SeekBar seekBar)
The callback that is invoked when the user finished a touch gesture on a SeekBar bound to this UIMediaControllerthrough bindSeekBar(SeekBar).
void
onSkipNextClicked(Viewview)
The callback that is invoked when the user clicks on anView bound to this UIMediaControllerthrough bindViewToSkipNext(View, int).
void
onSkipPrevClicked(Viewview)
The callback that is invoked when the user clicks on anView bound to this UIMediaControllerthrough bindViewToSkipPrev(View, int).

Inherited Method Summary

Public Constructors

publicUIMediaController(Activity activity)

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

Public Methods

public voidbindImageViewToImageOfCurrentItem(ImageViewview, int imageType, int placeHolderDrawableResId)

This method is deprecated.
Use bindImageViewToImageOfCurrentItem(ImageView, ImageHints, int)instead

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

Parameters
view theViewto bind
imageType the type of image, used by theImagePicker to choose the proper image
placeHolderDrawableResId the resource ID of aDrawable used as a placeholder if no image is available from the current item
Throws
IllegalStateException if this method is not called on the main thread

public voidbindImageViewToImageOfCurrentItem(ImageViewview, int imageType,View placeHolderView)

This method is deprecated.
Use bindImageViewToImageOfCurrentItem(ImageView, ImageHints, View)instead

Binds anImageView to an image of the current item. When an item is loaded, and there is aWebImage that is suitable to be displayed, theBitmapof that image will be fetched and set on theImageView. If the item contains multiple images, this class will choose one using the ImagePicker configured inCastMediaOptions, with the givenimageType.

Parameters
view theImageView
imageType type of image, used by theImagePicker to choose the proper image
placeHolderView theViewto show as a placeholder if no image is available from the current item
Throws
IllegalStateException if this method is not called on the main thread

public voidbindImageViewToImageOfCurrentItem(ImageViewview, ImageHints imageHints, int placeHolderDrawableResId)

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

Parameters
view theViewto bind
imageHints ImageHints used by theImagePicker to choose the proper image
placeHolderDrawableResId the resource ID of aDrawable used as a placeholder if no image is available from the current item
Throws
IllegalStateException if this method is not called on the main thread

public voidbindImageViewToImageOfCurrentItem(ImageViewview, ImageHints imageHints,View placeHolderView)

Binds anImageView to an image of the current item. When an item is loaded, and there is aWebImage that is suitable to be displayed, theBitmapof that image will be fetched and set on theImageView. If the item contains multiple images, this class will choose one using the ImagePicker configured inCastMediaOptions, with the givenimageType.

Parameters
view theImageView
imageHints ImageHints used by theImagePicker to choose the proper image
placeHolderView theViewto show as a placeholder if no image is available from the current item
Throws
IllegalStateException if this method is not called on the main thread

public voidbindImageViewToImageOfPreloadedItem(ImageViewview, int imageType, int placeHolderDrawableResId)

This method is deprecated.
Use bindImageViewToImageOfPreloadedItem(ImageView, ImageHints, int)instead

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

Parameters
view theViewto bind
imageType type of image, used by theImagePicker to choose the proper image
placeHolderDrawableResId the resource ID of aDrawable used as a placeholder if no image is available from the preloaded item
Throws
IllegalStateException if this method is not called on the main thread

public voidbindImageViewToImageOfPreloadedItem(ImageViewview, ImageHints imageHints, int placeHolderDrawableResId)

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

Parameters
view theViewto bind
imageHints ImageHints used by theImagePicker to choose the proper image
placeHolderDrawableResId the resource ID of aDrawable used as a placeholder if no image is available from the preloaded item
Throws
IllegalStateException if this method is not called on the main thread

public voidbindImageViewToMuteToggle(ImageView view)

Binds anImageView to mute and unmute the Cast receiver device volume.

TheImageView will be updated based on theCastSession connection state and muted state. AView.OnClickListener will also be set to theImageView so that when it is clicked, the listener will call onMuteToggleClicked(ImageView)to handle the click event. Do not call View.setOnClickListener(View.OnClickListener)on theImageView. To override the behavior, create a subclass of UIMediaControllerand override the onMuteToggleClicked(ImageView)method.

Parameters
view theImageView to bind
Throws
IllegalStateException if this method is not called on the main thread

public voidbindImageViewToPlayPauseToggle(ImageViewview, Drawable playDrawable,Drawable pauseDrawable,Drawable stopDrawable,View loadingIndicator, boolean hideViewWhenLoading)

Binds anImageView to toggle play / pause of the current item.

TheImageView will be updated based on theCastSession state and remote playback state. AView.OnClickListener will also be set to theImageView so that when it is clicked, the listener will call onPlayPauseToggleClicked(ImageView)to handle the click event. Do not call View.setOnClickListener(View.OnClickListener)on theImageView. To override the behavior, create a subclass of UIMediaControllerand override the onPlayPauseToggleClicked(ImageView)method.

Parameters
view theImageView to bind
playDrawable theDrawable to use when the state of the control is "play"
pauseDrawable theDrawable to use when the state of the control is "pause"
stopDrawable theDrawable to use when the state of the control is "stop live stream"; if set to null,the framework will display thepauseDrawablewhen a "stop live stream" icon is needed
loadingIndicator aViewthat should be displayed to indicate that a remote request is ongoing
hideViewWhenLoading trueif visibility ofimageViewshould be set to View.INVISIBLE when loading an item,falseif it should be set toView.VISIBLE when loading an item
Throws
IllegalStateException if this method is not called on the main thread

public voidbindProgressBar(ProgressBar view)

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

Parameters
view theProgressBar to bind
Throws
IllegalStateException if this method is not called on the main thread

public voidbindProgressBar(ProgressBarview, long progressUpdateStepMs)

Binds aProgressBar to the playback progress of the current item. Progress will be updated once per progressUpdateStepMsmilliseconds. If no item is loaded the progress of theProgressBar will be set to zero.

Parameters
view theProgressBar to bind
progressUpdateStepMs the interval between each update of the progress, in milliseconds
Throws
IllegalStateException if this method is not called on the main thread

public voidbindSeekBar(CastSeekBar view)

Binds a CastSeekBarto control the playback position of the current item.

The CastSeekBarwill be updated based on theCastSession state and remote playback progress. Progress will be updated once per second. If no item is loaded, the progress of the CastSeekBarwill be set to zero and the CastSeekBarwill be disabled.

The CastSeekBarwill be able to handle live content. When playing live streams, the seek bar will draw the seekable range properly, and seek is only allowed within the seekable range.

Parameters
view the CastSeekBarto bind
Throws
IllegalStateException if this method is not called on the main thread

public voidbindSeekBar(SeekBarview, long progressUpdateStepMs)

Binds aSeekBarto control the playback position of the current item.

TheSeekBarwill be updated based on theCastSession state and remote playback progress. Progress will be updated once per progressUpdateStepMsmilliseconds. If no item is loaded, the progress of theSeekBarwill be set to zero and theSeekBarwill be disabled. A SeekBar.OnSeekBarChangeListenerwill also be set to theSeekBarso that when the user interacts with theSeekBar,it will forward the listener events to this UIMediaControllerto handle the event. SeekBar.OnSeekBarChangeListener.onStopTrackingTouch(SeekBar)will be forwarded to onSeekBarStopTrackingTouch(SeekBar). SeekBar.OnSeekBarChangeListener.onStartTrackingTouch(SeekBar)will be forwarded to onSeekBarStartTrackingTouch(SeekBar). SeekBar.OnSeekBarChangeListener.onProgressChanged(SeekBar, int, boolean) will be forwarded to onSeekBarProgressChanged(SeekBar, int, boolean).Do not call SeekBar.setOnSeekBarChangeListener(SeekBar.OnSeekBarChangeListener)on the SeekBar.To override the behavior, create a subclass of UIMediaControllerand override the onSeekBarProgressChanged(SeekBar, int, boolean), onSeekBarStartTrackingTouch(SeekBar)and onSeekBarStopTrackingTouch(SeekBar)methods.

TheSeekBar's behavior will be undefined for live content. It should not be used in this case.

If the client wants to set the thumb on theSeekBarvia AbsSeekBar.setThumb(Drawable),it need to call the method before binding the SeekBar. After binding, the method should not be called.

Parameters
view theSeekBar to bind
progressUpdateStepMs the interval between each update of the progress, in milliseconds
Throws
IllegalStateException if this method is not called on the main thread

public voidbindSeekBar(CastSeekBar view, long progressUpdateStepMs)

Binds a CastSeekBarto control the playback position of the current item.

The CastSeekBarwill be updated based on theCastSession state and remote playback progress. Progress will be updated once per second. If no item is loaded, the progress of the CastSeekBarwill be set to zero and the CastSeekBarwill be disabled.

The CastSeekBarwill be able to handle live content. The ad breaks and seekable range will be drawn properly, and seek is only allowed in the seekable range.

Parameters
view the CastSeekBarto bind
progressUpdateStepMs the interval between each update of the progress, in milliseconds
Throws
IllegalStateException if this method is not called on the main thread

public voidbindSeekBar(SeekBar view)

Binds aSeekBarto control the playback position of the current item.

TheSeekBarwill be updated based on theCastSession state and remote playback progress. Progress will be updated once per second. If no item is loaded, the progress of theSeekBarwill be set to zero and theSeekBarwill be disabled. A SeekBar.OnSeekBarChangeListenerwill also be set to theSeekBarso that when the user interacts with theSeekBar,it will forward the listener events to this UIMediaControllerto handle the event. SeekBar.OnSeekBarChangeListener.onStopTrackingTouch(SeekBar)will be forwarded to onSeekBarStopTrackingTouch(SeekBar). SeekBar.OnSeekBarChangeListener.onStartTrackingTouch(SeekBar)will be forwarded to onSeekBarStartTrackingTouch(SeekBar). SeekBar.OnSeekBarChangeListener.onProgressChanged(SeekBar, int, boolean) will be forwarded to onSeekBarProgressChanged(SeekBar, int, boolean).Do not call SeekBar.setOnSeekBarChangeListener(SeekBar.OnSeekBarChangeListener)on the SeekBar.To override the behavior, create a subclass of UIMediaControllerand override the onSeekBarProgressChanged(SeekBar, int, boolean), onSeekBarStartTrackingTouch(SeekBar)and onSeekBarStopTrackingTouch(SeekBar)methods.

TheSeekBar's behavior will be undefined for live content. It should not be used in this case.

If the client wants to set the thumb on theSeekBarvia AbsSeekBar.setThumb(Drawable),it need to call the method before binding the SeekBar. After binding, the method should not be called.

Parameters
view theSeekBar to bind
Throws
IllegalStateException if this method is not called on the main thread

public voidbindTextViewToMetadataOfCurrentItem(TextViewview, String key)

Binds aTextViewto the metadata of the current item, keyed bykey.If metadata for keyis unavailable, the TextView will be left untouched.

Parameters
view theViewto bind
key the key of the metadata field to bind
Throws
IllegalStateException if this method is not called on the main thread

public voidbindTextViewToMetadataOfCurrentItem(TextViewview, List<String> keysInPreference)

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

Parameters
view theViewto bind
keysInPreference the list of keys in the order of preference
Throws
IllegalStateException if this method is not called on the main thread

public voidbindTextViewToMetadataOfPreloadedItem(TextViewview, List<String> keysInPreference)

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

Parameters
view theViewto bind
keysInPreference the list of keys in the order of preference
Throws
IllegalStateException if this method is not called on the main thread

public voidbindTextViewToMetadataOfPreloadedItem(TextViewview, String key)

Binds anTextViewto the metadata of the preloaded item, keyed bykey.If metadata for keyis unavailable, the TextView will be left untouched.

Parameters
view theViewto bind
key the key of the metadata field to bind
Throws
IllegalStateException if this method is not called on the main thread

public voidbindTextViewToSmartSubtitle(TextView textView)

Binds aTextViewto the most appropriate item inMediaMetadata for subtitle. For example the studio name for a movie or the artist name for a music track.

public voidbindTextViewToStreamDuration(TextView view,View liveStreamIndicator)

Binds aTextViewto the playback duration of the current item. If no item is loaded, or if the currently playing item is a live stream, then the text will be set to "--:--".

When playing a live stream item, ifliveStreamIndicatoris not null,thenviewwill be hidden and liveStreamIndicatorwill be shown to better indicate that a live stream is playing.

Parameters
view theTextView to bind
liveStreamIndicator ifViewto indicate that a live stream items is playing
Throws
IllegalStateException if this method is not called on the main thread

public voidbindTextViewToStreamDuration(TextView view)

Binds aTextViewto the playback duration of the current item. If no item is loaded, or if the currently playing item is a live stream, then the text will be set to "--:--".

Parameters
view theTextView to bind
Throws
IllegalStateException if this method is not called on the main thread

public voidbindTextViewToStreamPosition(TextView view, boolean updateWhileScrubbing)

Binds aTextViewto 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 theTextView to bind
updateWhileScrubbing if this is set totrue,theViewwill be put in the update-when-scrubbing set and will be updated to the position of a bound SeekBar or CastSeekBarwhile it is being scrubbed
Throws
IllegalStateException if this method is not called on the main thread

public voidbindTextViewToStreamPosition(TextView view, boolean updateWhileScrubbing, long progressUpdateStepMs)

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

Parameters
view theTextView to bind
updateWhileScrubbing if this is set totrue,theViewwill be put in the update-when-scrubbing set and will be updated to the position of a bound SeekBar or CastSeekBarwhile it is being scrubbed
progressUpdateStepMs the interval between each update of the progress, in milliseconds
Throws
IllegalStateException if this method is not called on the main thread

public voidbindViewToClosedCaption(Viewview)

Binds aViewto launching the TracksChooserDialogFragmentwhen clicked.

The view will be updated based on theCastSession state and the availability of audio and text tracks. AView.OnClickListener will also be set to the view so that when the view is clicked, it will call onClosedCaptionClicked(View)to handle the click event. Do not call View.setOnClickListener(View.OnClickListener)on the view. To override the behavior, create a subclass of UIMediaControllerand override the onClosedCaptionClicked(View)method.

Throws
IllegalStateException if this method is not called on the main thread

public voidbindViewToForward(Viewview, long skipStepMs)

Binds aViewto skip forward playback of the current itemskipStepMsmilliseconds.

TheViewwill be updated based on theCastSession state, the remote playback progress and whether it is livestream. AView.OnClickListener will also be set to theViewso that when it is clicked, the listener will call onForwardClicked(View, long)to handle the click event. Do not call View.setOnClickListener(View.OnClickListener)on theView.To override the behavior, create a subclass of UIMediaControllerand override the onForwardClicked(View, long)method.

Parameters
view theViewto bind
skipStepMs the time (in milliseconds) to skip forward
Throws
IllegalStateException if this method is not called on the main thread

public voidbindViewToLaunchExpandedController(View view)

Binds aViewto launching the expanded controllerActivity specified by the name in CastMediaOptions.getExpandedControllerActivityClassName().If the specified class name isnull,then clicking the button is a no-op.

TheViewwill be updated based on theCastSession state. AView.OnClickListener will also be set to theViewso that when it is clicked, the listener will call onLaunchExpandedControllerClicked(View)to handle the click event. Do not call View.setOnClickListener(View.OnClickListener)on theView.To override the behavior, create a subclass of UIMediaControllerand override the onLaunchExpandedControllerClicked(View)method.

Throws
IllegalStateException if this method is not called on the main thread

public voidbindViewToLoadingIndicator(Viewview)

Binds aView's visibility state toView.VISIBLE only when the remote receiver is either buffering, or loading the next item. Otherwise visibility of theViewwill be set toView.GONE.

Parameters
view theViewto bind
Throws
IllegalStateException if this method is not called on the main thread

public voidbindViewToRewind(Viewview, long skipStepMs)

Binds aViewto rewind playback of the current itemskipStepMsmilliseconds.

TheViewwill be updated based on theCastSession state, the remote playback state and whether it is livestream. AView.OnClickListener will also be set to theViewso that when it is clicked, the listener will call onRewindClicked(View, long)to handle the click event. Do not call View.setOnClickListener(View.OnClickListener)on theView.To override the behavior, create a subclass of UIMediaControllerand override the onRewindClicked(View, long)method.

Parameters
view theViewto bind
skipStepMs the time (in milliseconds) to rewind
Throws
IllegalStateException if this method is not called on the main thread

public voidbindViewToSkipNext(Viewview, int invisibleState)

Binds aViewto skip to the next item in the queue.

TheViewwill be updated based on theCastSession state, the remote playback state and the availability of the next queue item. A View.OnClickListener will also be set to theViewso that when it is clicked, the listener will call onSkipNextClicked(View)to handle the click event. Do not call View.setOnClickListener(View.OnClickListener)on theView.To override the behavior, create a subclass of UIMediaControllerand override the onSkipNextClicked(View)method.

Parameters
view theViewto bind
invisibleState eitherView.INVISIBLE orView.GONE; this parameter will be set as the visibility ofViewwhen there isn't a previous item in the queue
Throws
IllegalStateException if this method is not called on the main thread

public voidbindViewToSkipPrev(Viewview, int invisibleState)

Binds aViewto skip to the previous item in the queue.

TheViewwill be updated based on theCastSession state, the remote playabck state and the availability of the previous queue item. A View.OnClickListener will also be set to theViewso that when it is clicked, the listener will call onSkipPrevClicked(View)to handle the click event. Do not call View.setOnClickListener(View.OnClickListener)on theView.To override the behavior, create a subclass of UIMediaControllerand override the onSkipPrevClicked(View)method.

Parameters
view theViewto bind
invisibleState eitherView.INVISIBLE orView.GONE; this parameter will be set as the visibility ofViewwhen there isn't a previous item in the queue
Throws
IllegalStateException if this method is not called on the main thread

public voidbindViewToUIController(Viewview, UIControlleruiController)

Binds aViewto a UIController.This method is typically used when the uiControlleris used to implement a custom control button.

Parameters
view theViewto bind
uiController the UIControllerof theview
Throws
IllegalStateException if this method is not called on the main thread

public voidbindViewVisibilityToMediaSession(Viewview, int invisibleState)

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

Parameters
view theViewto bind
invisibleState eitherView.INVISIBLE orView.GONE, which will be set as the visibility ofviewwhen there isn't a media session
Throws
IllegalStateException if this method is not called on the main thread

public voidbindViewVisibilityToPreloadingEvent(Viewview, int invisibleState)

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

Parameters
view theViewto bind
invisibleState eitherView.INVISIBLE orView.GONE, which will be set as the visibility ofviewwhen there isn't a preloaded item
Throws
IllegalStateException if this method is not called on the main thread

public voiddispose()

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

Throws
IllegalStateException if this method is not called on the main thread

publicRemoteMediaClient getRemoteMediaClient()

Returns the managed RemoteMediaClientof the current activeCastSession.

Throws
IllegalStateException if this method is not called on the main thread

public booleanisActive()

Returns true if there is an active connected Cast Session.

Throws
IllegalStateException if this method is not called on the main thread

public voidonAdBreakStatusUpdated()

Called when updated ad break status information is received.

public voidonMetadataUpdated()

Called when updated media metadata is received.

public voidonPreloadStatusUpdated()

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 respond to preloading related event, such as displaying what will be played next in the UI.

public voidonQueueStatusUpdated()

Called when updated player queue status information is received.

public voidonSendingRemoteMediaRequest()

Called when there is an outgoing 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 voidonSessionEnded(CastSession session, int error)

public voidonSessionEnding(CastSession session)

public voidonSessionResumeFailed(CastSession session, int error)

public voidonSessionResumed(CastSession session, boolean wasSuspended)

public voidonSessionResuming(CastSession session,String sessionId)

public voidonSessionStartFailed(CastSession session, int error)

public voidonSessionStarted(CastSession session,String sessionId)

public voidonSessionStarting(CastSession session)

public voidonSessionSuspended(CastSession session, int reason)

public voidonStatusUpdated()

Called when updated player status information is received.

public voidsetPostRemoteMediaClientListener(RemoteMediaClient.Listener listener)

Sets a RemoteMediaClient.Listenerthat will be called after all the other registered listeners in the UIMediaControllerinstance are invoked. Also, the states of all the bound Viewinstances are guaranteed to be updated before this listener is invoked.

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

Throws
IllegalStateException if this method is not called on the main thread

Protected Methods

protected voidonClosedCaptionClicked(Viewview)

The callback that is invoked when the user clicks on anViewbound to this UIMediaControllerthrough bindViewToClosedCaption(View).

The default behavior is to launch the TracksChooserDialogFragmentif theActivityused to construct this UIMediaControlleris aFragmentActivity and the remote media is loaded.

Parameters
view theViewthat the user clicked

protected voidonForwardClicked(Viewview, long skipStepMs)

The callback that is invoked when the user clicks on anViewbound to this UIMediaControllerthrough bindViewToForward(View, long).

The default behavior is to call the RemoteMediaClient.seek(MediaSeekOptions)method of getRemoteMediaClient()if the remote media is loaded, with the position of getRemoteMediaClient().getApproximateStreamPosition() + skipStepMs.

Parameters
view theViewthat the user clicked
skipStepMs the amount of time, in milliseconds, that the playback position will move forward by when theViewis clicked

protected voidonLaunchExpandedControllerClicked(View view)

The callback that is invoked when the user clicks on anViewbound to this UIMediaControllerthrough bindViewToLaunchExpandedController(View).

The default behavior is to launch the expanded controllerActivity specified by the name in CastMediaOptions.getExpandedControllerActivityClassName()ofCastMediaOptions.

Parameters
view theViewthat the user clicked

protected voidonMuteToggleClicked(ImageView view)

The callback that is invoked when the user clicks on anImageView bound to this UIMediaControllerthrough bindImageViewToMuteToggle(ImageView).

The default behavior is to toggle the muted state of theCastSession if there is one and it is connected.

Parameters
view theImageView that the user clicked

protected voidonPlayPauseToggleClicked(ImageView view)

The callback that is invoked when the user clicks on anImageView bound to this UIMediaControllerthrough bindImageViewToPlayPauseToggle(ImageView, Drawable, Drawable, Drawable, View, boolean).

The default behavior is to call the RemoteMediaClient.togglePlayback()method of getRemoteMediaClient()if the remote media is loaded.

Parameters
view theImageView that the user clicked

protected voidonRewindClicked(Viewview, long skipStepMs)

The callback that is invoked when the user clicks on anViewbound to this UIMediaControllerthrough bindViewToRewind(View, long).

The default behavior is to call the RemoteMediaClient.seek(MediaSeekOptions)method of getRemoteMediaClient()if the remote media is loaded, with the position of getRemoteMediaClient().getApproximateStreamPosition() - skipStepMs.

Parameters
view theViewthat the user clicked
skipStepMs the amount of time, in milliseconds, that the playback position will move backward by when theViewis clicked

protected voidonSeekBarProgressChanged(SeekBarseekBar, int progress, boolean fromUser)

The callback that is invoked on progress change of aSeekBar bound to this UIMediaControllerthrough bindSeekBar(SeekBar).

The default behavior is: if the progress change comes from a user action, use progressto update the progress of all views in the update-when-scrubbing set.

Parameters
seekBar theSeekBar that the user is scrubbing
progress the current progress level
fromUser trueif the progress change was initiated by the user

protected voidonSeekBarStartTrackingTouch(SeekBar seekBar)

The callback that is invoked when the user starts a touch gesture on a SeekBar bound to this UIMediaControllerthrough bindSeekBar(SeekBar).

The default behavior is to detach theseekBarand all the views in the update-when-scrubbing set from theCastSession to stop receiving furthur playback progress updates.

Parameters
seekBar theSeekBar that the user is scrubbing

protected voidonSeekBarStopTrackingTouch(SeekBar seekBar)

The callback that is invoked when the user finished a touch gesture on a SeekBar bound to this UIMediaControllerthrough bindSeekBar(SeekBar).

The default behavior is to reattach theseekBarand all the views in the update-when-scrubbing set to theCastSession to receive furthur playback progress updates. Then the method will call RemoteMediaClient.seek(MediaSeekOptions)method of getRemoteMediaClient()if the remote media is loaded.

Parameters
seekBar theSeekBar that the user is scrubbing

protected voidonSkipNextClicked(Viewview)

The callback that is invoked when the user clicks on anViewbound to this UIMediaControllerthrough bindViewToSkipNext(View, int).

The default behavior is to call the RemoteMediaClient.queueNext(JSONObject)method of getRemoteMediaClient()if the remote media is loaded, with customDataofnull.

Parameters
view theViewthat the user clicked

protected voidonSkipPrevClicked(Viewview)

The callback that is invoked when the user clicks on anViewbound to this UIMediaControllerthrough bindViewToSkipPrev(View, int).

The default behavior is to call the RemoteMediaClient.queuePrev(JSONObject)method of getRemoteMediaClient()if the remote media is loaded, with customDataofnull.

Parameters
view theViewthat the user clicked