public class

MiniControllerFragment

extends Fragment
implements ControlButtonsContainer
java.lang.Object
   ↳ android.support.v4.app.Fragment
     ↳ com.google.android.gms.cast.framework.media.widget.MiniControllerFragment

Class Overview

A fragment that provides remote control functionality. This fragment provides an image for the album art, a ProgressBar for playback progression, and three configurable control buttons. If developers want to use this fragment, they should add it to their layout XML file, and the CastContext will automatically manage its state, and handle any user interactions.

 <fragment
     android:id="@+id/cast_mini_controller"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:visibility="gone"
     class="com.google.android.gms.cast.framework.media.widget.MiniControllerFragment">
 

Configurable control buttons

The fragment can show up to three control buttons, from start to end. By default the fragment shows a play/pause toggle button. Developers can use the attribute castControlButtons to override what buttons to show. 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, a play/pause toggle button and a forward button, from start to end:

 <array name="cast_mini_controller_control_buttons">
     <item>@id/cast_button_type_rewind_30_seconds</item>
     <item>@id/cast_button_type_play_pause_toggle</item>
     <item>@id/cast_button_type_forward_30_seconds</item>
 </array>
 ...
 <fragment
     android:id="@+id/cast_mini_controller"
     ...
     app:castControlButtons="@array/cast_mini_controller_control_buttons"
     class="com.google.android.gms.cast.framework.media.widget.MiniControllerFragment">
 
The array must contain exactly three 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 fragment 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 onCreateView(LayoutInflater, ViewGroup, 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);
         ...
     }
 }

 // MyMiniControllerFragment.java
 class MyMiniControllerFragment extends MiniControllerFragment {
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
         super.onCreateView(inflater, container, savedInstanceState);
         ImageView customButtonView = getButtonImageViewAt(2);
         MyCustomUIController myCustomUiController = new MyCustomUIController(customButtonView);
         getUIMediaController().bindViewToUIController(customButtonView, myCustomUiController);
         ...
     }
 }
 

Show or hide album art

The album art can be hidden by setting attribute castShowImageThumbnail to false:

 ...
 app:castShowImageThumbnail="false"
 ...
 
If the album art is shown, then the first control button will not be displayed.

The fragment will be visible when a media session starts, and will be invisible when a media session ends.

Summary

XML Attributes
Attribute Name Related Method Description
com.google.android.gms:castBackground  
com.google.android.gms:castButtonColor  
com.google.android.gms:castClosedCaptionsButtonDrawable  
com.google.android.gms:castControlButtons  
com.google.android.gms:castForward30ButtonDrawable  
com.google.android.gms:castLargePauseButtonDrawable  
com.google.android.gms:castLargePlayButtonDrawable  
com.google.android.gms:castLargeStopButtonDrawable  
com.google.android.gms:castMuteToggleButtonDrawable  
com.google.android.gms:castPauseButtonDrawable  
com.google.android.gms:castPlayButtonDrawable  
com.google.android.gms:castProgressBarColor  
com.google.android.gms:castRewind30ButtonDrawable  
com.google.android.gms:castShowImageThumbnail  
com.google.android.gms:castSkipNextButtonDrawable  
com.google.android.gms:castSkipPreviousButtonDrawable  
com.google.android.gms:castStopButtonDrawable  
com.google.android.gms:castSubtitleTextAppearance  
com.google.android.gms:castTitleTextAppearance  
Public Constructors
MiniControllerFragment()
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.
UIMediaController getUIMediaController()
Returns the UIMediaController used to bind views in this container.
View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
void onDestroy()
void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState)
[Expand]
Inherited Methods
From class android.support.v4.app.Fragment
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.view.View.OnCreateContextMenuListener
From interface com.google.android.gms.cast.framework.media.widget.ControlButtonsContainer

XML Attributes

com.google.android.gms:castBackground

Related Methods

com.google.android.gms:castButtonColor

Related Methods

com.google.android.gms:castClosedCaptionsButtonDrawable

Related Methods

com.google.android.gms:castControlButtons

Related Methods

com.google.android.gms:castForward30ButtonDrawable

Related Methods

com.google.android.gms:castLargePauseButtonDrawable

Related Methods

com.google.android.gms:castLargePlayButtonDrawable

Related Methods

com.google.android.gms:castLargeStopButtonDrawable

Related Methods

com.google.android.gms:castMuteToggleButtonDrawable

Related Methods

com.google.android.gms:castPauseButtonDrawable

Related Methods

com.google.android.gms:castPlayButtonDrawable

Related Methods

com.google.android.gms:castProgressBarColor

Related Methods

com.google.android.gms:castRewind30ButtonDrawable

Related Methods

com.google.android.gms:castShowImageThumbnail

Related Methods

com.google.android.gms:castSkipNextButtonDrawable

Related Methods

com.google.android.gms:castSkipPreviousButtonDrawable

Related Methods

com.google.android.gms:castStopButtonDrawable

Related Methods

com.google.android.gms:castSubtitleTextAppearance

Related Methods

com.google.android.gms:castTitleTextAppearance

Related Methods

Public Constructors

public MiniControllerFragment ()

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 int: the index of the slot in this container.
Returns
ImageView
Throws
IndexOutOfBoundsException

public final int getButtonSlotCount ()

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

Returns
int

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 int: the index of the slot in this container.
Returns
int
Throws
IndexOutOfBoundsException

public UIMediaController getUIMediaController ()

Returns the UIMediaController used to bind views in this container.

Returns
UIMediaController

public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

Parameters
inflater LayoutInflater
container ViewGroup
savedInstanceState Bundle
Returns
View

public void onDestroy ()

public void onInflate (Context context, AttributeSet attrs, Bundle savedInstanceState)

Parameters
context Context
attrs AttributeSet
savedInstanceState Bundle