java.lang.Object | ||||||||
↳ | android.content.Context | |||||||
↳ | android.content.ContextWrapper | |||||||
↳ | android.view.ContextThemeWrapper | |||||||
↳ | android.app.Activity | |||||||
↳ | android.support.v4.app.SupportActivity | |||||||
↳ | android.support.v4.app.FragmentActivity | |||||||
↳ | android.support.v7.app.AppCompatActivity | |||||||
↳ | com.google.android.gms.cast.framework.media.widget.ExpandedControllerActivity |
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:
castExpandedControllerToolbarStyle
to ThemeOverlay.AppCompat.Dark.ActionBar
in your theme to use light text and icon color in the
Toolbar.
// 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>
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; } }
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"> @style/ThemeOverlay.AppCompat.Dark.ActionBar </item> </style>
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"> <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
.
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 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"> <item>@id/cast_button_type_empty</item> <item>@id/cast_button_type_rewind_30_seconds</item> <item>@id/cast_button_type_custom</item> <item>@id/cast_button_type_empty</item> </array> // MyCustomUIController.java class MyCustomUIController extends UIController { private final View mView; public MyCustomUIController(View view) { mView = view; } @Override public onMediaStatusUpdated() { // Update the state of mView based on the latest the media status. ... mView.setVisible(false); ... } } // MyExpandedControllerActivity.java class MyExpandedControllerActivity extends ExpandedControllerActivity { @Override public void onCreate() { super.onCreate(); ImageView customButtonView = getButtonImageViewAt(2); MyCustomUIController myCustomUiController = new MyCustomUIController(customButtonView); getUIMediaController().bindViewToUIController(customButtonView, myCustomUiController); ... } }
CastContext
can manage the lifecycle and
presentation of this activity.
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
com.google.android.gms:castButtonColor | |||||||||||
com.google.android.gms:castClosedCaptionsButtonDrawable | |||||||||||
com.google.android.gms:castControlButtons | |||||||||||
com.google.android.gms:castForward30ButtonDrawable | |||||||||||
com.google.android.gms:castMuteToggleButtonDrawable | |||||||||||
com.google.android.gms:castPauseButtonDrawable | |||||||||||
com.google.android.gms:castPlayButtonDrawable | |||||||||||
com.google.android.gms:castRewind30ButtonDrawable | |||||||||||
com.google.android.gms:castSeekBarProgressDrawable | |||||||||||
com.google.android.gms:castSeekBarThumbDrawable | |||||||||||
com.google.android.gms:castSkipNextButtonDrawable | |||||||||||
com.google.android.gms:castSkipPreviousButtonDrawable | |||||||||||
com.google.android.gms:castStopButtonDrawable |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the
ImageView of the button at slotIndex in this container. | |||||||||||
Returns the number of slots to hold control buttons in this container.
| |||||||||||
Returns the type of the button at
slotIndex in this container. | |||||||||||
Returns the
SeekBar instance. | |||||||||||
Returns the
TextView that displays the status text. | |||||||||||
Returns the
UIMediaController used to bind views in this container. | |||||||||||
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
Returns the number of slots to hold control buttons in this container.
Returns | |
---|---|
int |
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 |
int :
the index of the slot in this container. |
Returns | |
---|---|
int |
Throws | |
---|---|
IndexOutOfBoundsException |
Returns the TextView
that displays the status text.
Returns | |
---|---|
TextView |
Returns the UIMediaController
used to bind views in this container.
Returns | |
---|---|
UIMediaController |
Parameters | |
---|---|
item |
MenuItem
|
Returns | |
---|---|
boolean |
Parameters | |
---|---|
hasFocus |
boolean
|
Parameters | |
---|---|
savedInstanceState |
Bundle
|