MediaRouteButton
public class MediaRouteButton extends View
The media route button allows the user to select routes and to control the currently selected route.
The application must specify the kinds of routes that the user should be allowed to select by specifying a selector with the setRouteSelector method.
When the default route is selected, the button will appear in an inactive state indicating that the application is not connected to a route. Clicking on the button opens a MediaRouteChooserDialog to allow the user to select a route. If no non-default routes match the selector and it is not possible for an active scan to discover any matching routes, then the button is disabled.
When a non-default route is selected, the button will appear in an active state indicating that the application is connected to a route of the kind that it wants to use. The button may also appear in an intermediary connecting state if the route is in the process of connecting to the destination but has not yet completed doing so. In either case, clicking on the button opens a MediaRouteControllerDialog to allow the user to control or disconnect from the current route.
Prerequisites
To use the media route button, the containing activity must be a subclass ofFragmentActivity.
| See also | |
|---|---|
MediaRouteActionProvider |
Summary
Public constructors |
|---|
MediaRouteButton(@NonNull Context context) |
MediaRouteButton(@NonNull Context context, @Nullable AttributeSet attrs) |
MediaRouteButton( |
Public methods |
|
|---|---|
void |
This method is deprecated. Use |
@NonNull MediaRouteDialogFactory |
Gets the media route dialog factory to use when showing the route chooser or controller dialog. |
@NonNull MediaRouteSelector |
Gets the media route selector for filtering the routes that the user can select using the media route chooser dialog. |
void |
|
void |
|
void |
|
boolean |
|
void |
This method is deprecated. The visibility of the button no longer depends on the availability of routes. |
void |
setDialogFactory(@NonNull MediaRouteDialogFactory factory)Sets the media route dialog factory to use when showing the route chooser or controller dialog. |
void |
Sets a drawable to use as the remote route indicator. |
void |
setRouteSelector(@NonNull MediaRouteSelector selector)Sets the media route selector for filtering the routes that the user can select using the media route chooser dialog. |
void |
setVisibility(int visibility) |
boolean |
Show the route chooser or controller dialog. |
Protected methods |
|
|---|---|
void |
|
@NonNull int[] |
onCreateDrawableState(int extraSpace) |
void |
|
void |
onMeasure(int widthMeasureSpec, int heightMeasureSpec) |
boolean |
verifyDrawable(@NonNull Drawable who) |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
MediaRouteButton
public MediaRouteButton(@NonNull Context context, @Nullable AttributeSet attrs)
MediaRouteButton
public MediaRouteButton(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr
)
Public methods
public void enableDynamicGroup()Enables dynamic group feature. With this enabled, a different set of MediaRouteChooserDialog and MediaRouteControllerDialog is shown when the button is clicked. If a media route provider supports dynamic group, the users can use that feature with the dialogs.
getDialogFactory
public @NonNull MediaRouteDialogFactory getDialogFactory()
Gets the media route dialog factory to use when showing the route chooser or controller dialog.
| Returns | |
|---|---|
@NonNull MediaRouteDialogFactory |
The dialog factory, never null. |
getRouteSelector
public @NonNull MediaRouteSelector getRouteSelector()
Gets the media route selector for filtering the routes that the user can select using the media route chooser dialog.
| Returns | |
|---|---|
@NonNull MediaRouteSelector |
The selector, never null. |
setDialogFactory
public void setDialogFactory(@NonNull MediaRouteDialogFactory factory)
Sets the media route dialog factory to use when showing the route chooser or controller dialog.
| Parameters | |
|---|---|
@NonNull MediaRouteDialogFactory factory |
The dialog factory, must not be null. |
setRemoteIndicatorDrawable
public void setRemoteIndicatorDrawable(@Nullable Drawable d)
Sets a drawable to use as the remote route indicator.
setRouteSelector
public void setRouteSelector(@NonNull MediaRouteSelector selector)
Sets the media route selector for filtering the routes that the user can select using the media route chooser dialog.
| Parameters | |
|---|---|
@NonNull MediaRouteSelector selector |
The selector, must not be null. |
showDialog
public boolean showDialog()
Show the route chooser or controller dialog.
If the default route is selected, then shows the route chooser dialog. Otherwise, shows the route controller dialog to offer the user a choice to disconnect from the route or perform other control actions such as setting the route's volume.
Dialog types can be set by setting MediaRouterParams to the router.
The application can customize the dialogs by calling setDialogFactory to provide a customized dialog factory.
| Returns | |
|---|---|
boolean |
True if the dialog was actually shown. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if the activity is not a subclass of |
| See also | |
|---|---|
setDialogType |
|
setOutputSwitcherEnabled |