public abstract class

ExpandedControllerActivity

extends AppCompatActivity
implements ControlButtonsContainer
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.view.ContextThemeWrapper
         ↳ android.app.Activity
           ↳ android.support.v4.app.FragmentActivity
             ↳ android.support.v7.app.AppCompatActivity
               ↳ com.google.android.gms.cast.framework.media.widget.ExpandedControllerActivity

Class Overview

This abstract class provides most of the implementation of an expanded controller, which is an out-of-the-box remote player 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="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto" >
     <item
     android:id="@+id/media_route_menu_item"
     app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
     app:showAsAction="always" />
 </menu>
 

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 {
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         super.onCreateOptionsMenu(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 always use a dark theme Toolbar, developers need to set a overlay theme to the toolbar to use light text and icon color.:
 // my_styles.xml
 <style name="Theme.CastVideosTheme" parent="Theme.AppCompat.Light.NoActionBar">
     <item name="castExpandedControllerToolbarStyle">
         @style/ThemeOverlay.AppCompat.Dark.ActionBar
     </item>
 </style>
 

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 left to right. Developers can use the attribute castControlButtons to override what buttons to show in them. 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">
     <item>@id/cast_button_type_empty</item>
     <item>@id/cast_button_type_rewind_30_seconds</item>
     <item>@id/cast_button_type_forward_30_seconds</item>
     <item>@id/cast_button_type_empty</item>
 </array>
 ...
 // styles.xml
 <style name="Theme.MyTheme">
     <item name="castExpandedControllerStyle">
         @style/CustomCastExpandedController
     </item>
 </style>
 ...
 <style name="CustomCastExpandedController" parent="CastExpandedController">
     <item name="castControlButtons">
         @array/cast_expanded_controller_control_buttons
     </item>
 </style>
 
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.

CastContext can manage the lifecycle and presentation of this activity.

Summary

[Expand]
Inherited Constants
From class android.app.Activity
From class android.content.Context
From interface android.content.ComponentCallbacks2
[Expand]
Inherited Fields
From class android.app.Activity
Public Constructors
ExpandedControllerActivity()
Public Methods
final ImageView getButtonImageViewAt(int slotIndex)
Returns the ImageView of the button at slotIndex in this container.
final int getButtonSlotCount()
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.
SeekBar getSeekBar()
Returns the SeekBar instance.
TextView getStatusTextView()
Returns the TextView that displays the status text.
UIMediaController getUIMediaController()
Returns the UIMediaController used to bind views in this container.
boolean onOptionsItemSelected(MenuItem item)
void onWindowFocusChanged(boolean hasFocus)
Protected Methods
void onCreate(Bundle savedInstanceState)
void onDestroy()
void onPause()
void onResume()
[Expand]
Inherited Methods
From class android.support.v7.app.AppCompatActivity
From class android.support.v4.app.FragmentActivity
From class android.app.Activity
From class android.view.ContextThemeWrapper
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.support.v7.app.AppCompatCallback
From interface android.support.v4.app.TaskStackBuilder.SupportParentable
From interface android.support.v7.app.ActionBarDrawerToggle.DelegateProvider
From interface android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback
From interface android.support.v4.app.ActivityCompatApi23.RequestPermissionsRequestCodeValidator
From interface android.view.LayoutInflater.Factory2
From interface android.view.Window.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.View.OnCreateContextMenuListener
From interface android.content.ComponentCallbacks2
From interface com.google.android.gms.cast.framework.media.widget.ControlButtonsContainer
From interface android.view.LayoutInflater.Factory
From interface android.content.ComponentCallbacks

Public Constructors

public ExpandedControllerActivity ()

Public Methods

public final ImageView getButtonImageViewAt (int slotIndex)

Returns the ImageView of the button at slotIndex in this container. The ImageView is defined in the layout of the Activity which implements this interface.

Parameters
slotIndex the index of the slot in this container.
Throws
IndexOutOfBoundsException

public final int getButtonSlotCount ()

Returns the number of slots to hold control buttons in this container.

public final int getButtonTypeAt (int slotIndex)

Returns the type of the button at slotIndex in this container.

Button types are defined as one of the 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.

Parameters
slotIndex the index of the slot in this container.
Throws
IndexOutOfBoundsException

public SeekBar getSeekBar ()

Returns the SeekBar instance.

public TextView getStatusTextView ()

Returns the TextView that displays the status text.

public UIMediaController getUIMediaController ()

Returns the UIMediaController used to bind views in this container.

public boolean onOptionsItemSelected (MenuItem item)

public void onWindowFocusChanged (boolean hasFocus)

Protected Methods

protected void onCreate (Bundle savedInstanceState)

protected void onDestroy ()

protected void onPause ()

protected void onResume ()