public abstract class ExpandedControllerActivity extends AppCompatActivity
implements ControlButtonsContainer

This abstract class provides most of the implementation of an expanded controller, which is an out-of-the-box remote player, used when casting media to a cast device. The expanded controller contains a dark Toolbar, a background album art image, a seek bar control, a play/pause toggle button, and up to 4 configurable control buttons. To fully implement an expanded controller, developers should do the following:

  • Subclass this class to add a cast button in its toolbar.
  • Set attribute castExpandedControllerToolbarStyle to ThemeOverlay.AppCompat.Dark.ActionBar in your theme to use light text and icon color in the Toolbar.

Define cast button menu xml

Developers need to define a menu xml that contains a cast button for the expanded controller Activity:
 // cast_expanded_controller_menu.xml
 <menu xmlns:android="//schemas.android.com/apk/res/android"
       xmlns:app="//schemas.android.com/apk/res-auto" >
     app:showAsAction="always" />

Set up the cast button

Developers need to subclass ExpandedControllerActivity to set up the Cast button, and register the Activity in the application's manifest file:
 // MyExpandedControllerActivity.java
 class MyExpandedControllerActivity extends ExpandedControllerActivity {
     public boolean onCreateOptionsMenu(Menu menu) {
         getMenuInflater().inflate(R.menu.cast_expanded_controller_menu, menu);
         CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.media_route_menu_item);
         return true;

Set Toolbar theme

Since this Activity defaults to a dark theme Toolbar, developers need to set an overlay theme for the toolbar to use light text and a light icon color:
 // my_styles.xml
 <style name="Theme.CastVideosTheme" parent="Theme.AppCompat.Light.NoActionBar">
     <item name="castExpandedControllerToolbarStyle">

Configurable control buttons

The Activity has five slots to show control buttons. The middle slot always shows a play/pause toggle button and is non-configurable. The other four slots are configurable by the sender app. By default the Activity shows a closed caption button, a skip to the previous item button, a skip to the next item button, and a mute toggle button in these slots, from start to end. Developers can use the attribute castControlButtons to override which buttons to show in which slots. The list of supported control buttons are defined as ID resources:

@id/cast_button_type_empty: Not placing a button in this slot.
@id/cast_button_type_custom: A custom button.
@id/cast_button_type_play_pause_toggle: A button that toggles playback.
@id/cast_button_type_skip_previous: A button that skips to the previous item in the queue.
@id/cast_button_type_skip_next: A button that skips to the next item in the queue.
@id/cast_button_type_rewind_30_seconds: A button that rewinds the playback by 30 seconds.
@id/cast_button_type_forward_30_seconds: A button that skips forward the playback by 30 seconds.
@id/cast_button_type_mute_toggle: A button that mutes and unmutes the remote receiver.
@id/cast_button_type_closed_caption: A button that opens a dialog to select text and audio tracks.

Here is an example of showing a rewind button in the second slot, a forward button in the third slot, and leaving the first and last slot empty:

 // arrays.xml
 <array name="cast_expanded_controller_control_buttons">
 // styles.xml
 <style name="Theme.MyTheme">
     <item name="castExpandedControllerStyle">
 <style name="CustomCastExpandedController" parent="CastExpandedController">
     <item name="castControlButtons">
The array must contain exactly four items, otherwise a runtime exception will be thrown. If you don't want to show a button in a slot, use @id/cast_button_type_empty.

Add custom control buttons

This activity supports adding custom control buttons which are not provided by the SDK, such as a "thumb up" button.

1. Specify a slot to contain a custom button using @id/cast_button_type_custom in the castControlButtons attribute. You can then use getButtonImageViewAt(int) to obtain the ImageView for that custom button.

2. Implement a subclass of UIController. The UIController contains methods that are called by the SDK when the state of the cast session or media session changes. Your subclass of UIController should take a ImageView as one of the parameters, and update its state as needed.

3. Override onCreate(Bundle), call getButtonImageViewAt(int) to get the view object of the button, and then call UIMediaController.bindViewToUIController(View, UIController) to associate the view with your custom UIController.

4. See MediaIntentReceiver for how to handle the action from your custom button.

Here is an example of associating a button at slot 2 to a UIController called MyCustomUIController:

 // arrays.xml
 <array name="cast_expanded_controller_control_buttons">

 // MyCustomUIController.java
 class MyCustomUIController extends UIController {
     private final View mButton;

     public MyCustomUIController(View button) {
         mButton = button;
         // Set the drawable and onClickListener on the button.

     public onMediaStatusUpdated() {
         // Update the state of mButton based on the latest the media status.

 // MyExpandedControllerActivity.java
 class MyExpandedControllerActivity extends ExpandedControllerActivity {
     public void onCreate(Bundle savedInstanceState) {
         ImageView customButtonView = getButtonImageViewAt(2);
         MyCustomUIController myCustomUiController = new MyCustomUIController(customButtonView);
         getUIMediaController().bindViewToUIController(customButtonView, myCustomUiController);

CastContext can manage the lifecycle and presentation of this activity.

XML Attribute Summary

Inherited Constant Summary

Inherited Field Summary

Public Constructor Summary

Public Method Summary

final ImageView
getButtonImageViewAt(int slotIndex)
Returns the ImageView of the button at slotIndex in this container.
final int
Returns the number of slots to hold control buttons in this container.
final int
getButtonTypeAt(int slotIndex)
Returns the type of the button at slotIndex in this container.
This method is deprecated. The expanded controller no longer uses SeekBar. The SeekBar returned by this method is only a dummy instance. Clients should not access the SeekBar.
Returns the TextView that displays the status text.
Returns the UIMediaController used to bind views in this container.
onWindowFocusChanged(boolean hasFocus)

Protected Method Summary

onCreate(Bundle savedInstanceState)

Inherited Method Summary

XML Attributes