MediaRouteProvider
public abstract class MediaRouteProvider
Media route providers are used to publish additional media routes for use within an application. Media route providers may also be declared as a service to publish additional media routes to all applications in the system.
The purpose of a media route provider is to discover media routes that satisfy the criteria specified by the current MediaRouteDiscoveryRequest and publish a MediaRouteProviderDescriptor with information about each route by calling setDescriptor to notify the currently registered Callback.
The provider should watch for changes to the discovery request by implementing onDiscoveryRequestChanged and updating the set of routes that it is attempting to discover. It should also handle route control requests such as volume changes or media control intents by implementing onCreateRouteController to return a RouteController for a particular route.
A media route provider can support dynamic group that allows the user to add or remove a route from the selected route dynamically. To control dynamic group, DynamicGroupRouteController returned by onCreateDynamicGroupRouteController is used instead of RouteController.
A media route provider may be used privately within the scope of a single application process by calling MediaRouter.addProvider to add it to the local MediaRouter. A media route provider may also be made available globally to all applications by registering a MediaRouteProviderService in the provider's manifest. When the media route provider is registered as a service, all applications that use the media router API will be able to discover and used the provider's routes without having to install anything else.
This object must only be accessed on the main thread.
Summary
Nested types |
|---|
public abstract class MediaRouteProvider.CallbackCallback which is invoked when route information becomes available or changes. |
public abstract class MediaRouteProvider.DynamicGroupRouteController extends MediaRouteProvider.RouteControllerProvides control over a dynamic group route. |
public final class MediaRouteProvider.DynamicGroupRouteController.DynamicRouteDescriptorContains a route, its selection state and its capabilities. |
|
Builder for |
public final class MediaRouteProvider.ProviderMetadataDescribes properties of the route provider's implementation. |
public abstract class MediaRouteProvider.RouteControllerProvides control over a particular route. |
public final class MediaRouteProvider.RouteControllerOptionsHolds parameters for creating |
public final class MediaRouteProvider.RouteControllerOptions.BuilderBuilder for |
Public constructors |
|---|
MediaRouteProvider(@NonNull Context context)Creates a media route provider. |
Public methods |
|
|---|---|
final @NonNull Context |
Gets the context of the media route provider. |
final @Nullable MediaRouteProviderDescriptor |
Gets the provider's descriptor. |
final @Nullable MediaRouteDiscoveryRequest |
Gets the current discovery request which informs the provider about the kinds of routes to discover and whether to perform active scanning. |
final @NonNull Handler |
Gets the provider's handler which is associated with the main thread. |
final @NonNull MediaRouteProvider.ProviderMetadata |
Gets some metadata about the provider's implementation. |
@Nullable MediaRouteProvider.DynamicGroupRouteController |
onCreateDynamicGroupRouteController(Creates a |
@Nullable MediaRouteProvider.DynamicGroupRouteController |
onCreateDynamicGroupRouteController(Creates a |
@Nullable MediaRouteProvider.RouteController |
onCreateRouteController(@NonNull String routeId)Called by the media router to obtain a route controller for a particular route. |
@Nullable MediaRouteProvider.RouteController |
onCreateRouteController(Creates a |
void |
Called by the media router when the |
final void |
setCallback(@Nullable MediaRouteProvider.Callback callback)Sets a callback to invoke when the provider's descriptor changes. |
final void |
setDescriptor(@Nullable MediaRouteProviderDescriptor descriptor)Sets the provider's descriptor. |
final void |
Sets a discovery request to inform the provider about the kinds of routes that its clients would like to discover and whether to perform active scanning. |
Public constructors
Public methods
getContext
public final @NonNull Context getContext()
Gets the context of the media route provider.
getDescriptor
public final @Nullable MediaRouteProviderDescriptor getDescriptor()
Gets the provider's descriptor.
The descriptor describes the state of the media route provider and the routes that it publishes. Watch for changes to the descriptor by registering a callback with setCallback.
| Returns | |
|---|---|
@Nullable MediaRouteProviderDescriptor |
The media route provider descriptor, or null if none. |
| See also | |
|---|---|
onDescriptorChanged |
getDiscoveryRequest
public final @Nullable MediaRouteDiscoveryRequest getDiscoveryRequest()
Gets the current discovery request which informs the provider about the kinds of routes to discover and whether to perform active scanning.
| Returns | |
|---|---|
@Nullable MediaRouteDiscoveryRequest |
The current discovery request, or null if no discovery is needed at this time. |
| See also | |
|---|---|
onDiscoveryRequestChanged |
getHandler
public final @NonNull Handler getHandler()
Gets the provider's handler which is associated with the main thread.
getMetadata
public final @NonNull MediaRouteProvider.ProviderMetadata getMetadata()
Gets some metadata about the provider's implementation.
onCreateDynamicGroupRouteController
public @Nullable MediaRouteProvider.DynamicGroupRouteController onCreateDynamicGroupRouteController(
@NonNull String initialMemberRouteId
)
Creates a DynamicGroupRouteController.
It is equivalent to onCreateDynamicGroupRouteController, except it doesn't take RouteControllerOptions.
This method is only called when the subclass doesn't implement onCreateDynamicGroupRouteController.
| Returns | |
|---|---|
@Nullable MediaRouteProvider.DynamicGroupRouteController |
|
onCreateDynamicGroupRouteController
public @Nullable MediaRouteProvider.DynamicGroupRouteController onCreateDynamicGroupRouteController(
@NonNull String initialMemberRouteId,
@NonNull MediaRouteProvider.RouteControllerOptions routeControllerOptions
)
Creates a DynamicGroupRouteController.
It will be called from an app or MediaRouter when a single route or a single static group is selected.
| Parameters | |
|---|---|
@NonNull String initialMemberRouteId |
initially selected route's id. |
@NonNull MediaRouteProvider.RouteControllerOptions routeControllerOptions |
the parameters to be used to create the route controller. |
| Returns | |
|---|---|
@Nullable MediaRouteProvider.DynamicGroupRouteController |
|
onCreateRouteController
public @Nullable MediaRouteProvider.RouteController onCreateRouteController(@NonNull String routeId)
Called by the media router to obtain a route controller for a particular route.
The media router will invoke the onRelease method of the route controller when it is no longer needed to allow it to free its resources.
| Returns | |
|---|---|
@Nullable MediaRouteProvider.RouteController |
The route controller. Returns null if there is no such route or if the route cannot be controlled using the route controller interface. |
onCreateRouteController
public @Nullable MediaRouteProvider.RouteController onCreateRouteController(
@NonNull String routeId,
@NonNull MediaRouteProvider.RouteControllerOptions routeControllerOptions
)
Creates a RouteController.
It will be called from an app or MediaRouter when a single route is selected.
| Parameters | |
|---|---|
@NonNull String routeId |
the selected route's ID. |
@NonNull MediaRouteProvider.RouteControllerOptions routeControllerOptions |
the parameters to be used to create the route controller. |
| Returns | |
|---|---|
@Nullable MediaRouteProvider.RouteController |
|
onDiscoveryRequestChanged
public void onDiscoveryRequestChanged(@Nullable MediaRouteDiscoveryRequest request)
Called by the media router when the discovery request has changed.
Whenever an applications calls addCallback to register a callback, it also provides a selector to specify the kinds of routes that it is interested in. The media router combines all of these selectors together to generate a MediaRouteDiscoveryRequest and notifies each provider when a change occurs by calling setDiscoveryRequest which posts a message to invoke this method asynchronously.
The provider should examine the media control categories in the discovery request's selector to determine what kinds of routes it should try to discover and whether it should perform active or passive scans. In many cases, the provider may be able to save power by determining that the selector does not contain any categories that it supports and it can therefore avoid performing any scans at all.
| Parameters | |
|---|---|
@Nullable MediaRouteDiscoveryRequest request |
The new discovery request, or null if no discovery is needed at this time. |
| See also | |
|---|---|
MediaRouter |
setCallback
public final void setCallback(@Nullable MediaRouteProvider.Callback callback)
Sets a callback to invoke when the provider's descriptor changes.
| Parameters | |
|---|---|
@Nullable MediaRouteProvider.Callback callback |
The callback to use, or null if none. |
setDescriptor
public final void setDescriptor(@Nullable MediaRouteProviderDescriptor descriptor)
Sets the provider's descriptor.
The provider must call this method to notify the currently registered callback about the change to the provider's descriptor.
| Parameters | |
|---|---|
@Nullable MediaRouteProviderDescriptor descriptor |
The updated route provider descriptor, or null if none. |
| See also | |
|---|---|
onDescriptorChanged |
setDiscoveryRequest
public final void setDiscoveryRequest(@Nullable MediaRouteDiscoveryRequest request)
Sets a discovery request to inform the provider about the kinds of routes that its clients would like to discover and whether to perform active scanning.
| Parameters | |
|---|---|
@Nullable MediaRouteDiscoveryRequest request |
The discovery request, or null if no discovery is needed at this time. |
| See also | |
|---|---|
onDiscoveryRequestChanged |