public abstract class MediaRouteProvider extends Object
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(android.support.v7.media.MediaRouteProviderDescriptor)
to notify the currently registered MediaRouteProvider.Callback
.
The provider should watch for changes to the discovery request by implementing
onDiscoveryRequestChanged(android.support.v7.media.MediaRouteDiscoveryRequest)
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(java.lang.String)
to return a MediaRouteProvider.RouteController
for a particular route.
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.
Modifier and Type | Class and Description |
---|---|
static class |
MediaRouteProvider.Callback
Callback which is invoked when route information becomes available or changes.
|
static class |
MediaRouteProvider.ProviderMetadata
Describes properties of the route provider's implementation.
|
static class |
MediaRouteProvider.RouteController
Provides control over a particular route.
|
Constructor and Description |
---|
MediaRouteProvider(Context context)
Creates a media route provider.
|
Modifier and Type | Method and Description |
---|---|
Context |
getContext()
Gets the context of the media route provider.
|
MediaRouteProviderDescriptor |
getDescriptor()
Gets the provider's descriptor.
|
MediaRouteDiscoveryRequest |
getDiscoveryRequest()
Gets the current discovery request which informs the provider about the
kinds of routes to discover and whether to perform active scanning.
|
Handler |
getHandler()
Gets the provider's handler which is associated with the main thread.
|
MediaRouteProvider.ProviderMetadata |
getMetadata()
Gets some metadata about the provider's implementation.
|
MediaRouteProvider.RouteController |
onCreateRouteController(String routeId)
Called by the media router to obtain a route controller for a particular route.
|
MediaRouteProvider.RouteController |
onCreateRouteController(String routeId,
String routeGroupId)
Called by the media router to obtain a route controller for a particular route which is a
member of
MediaRouter.RouteGroup . |
void |
onDiscoveryRequestChanged(MediaRouteDiscoveryRequest request)
Called by the media router when the
discovery request
has changed. |
void |
setCallback(MediaRouteProvider.Callback callback)
Sets a callback to invoke when the provider's descriptor changes.
|
void |
setDescriptor(MediaRouteProviderDescriptor descriptor)
Sets the provider's descriptor.
|
void |
setDiscoveryRequest(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.
|
public final Context getContext()
public final Handler getHandler()
public final MediaRouteProvider.ProviderMetadata getMetadata()
public final void setCallback(@Nullable MediaRouteProvider.Callback callback)
callback
- The callback to use, or null if none.@Nullable public final MediaRouteDiscoveryRequest getDiscoveryRequest()
onDiscoveryRequestChanged(android.support.v7.media.MediaRouteDiscoveryRequest)
public final void setDiscoveryRequest(MediaRouteDiscoveryRequest request)
request
- The discovery request, or null if no discovery is needed at this time.onDiscoveryRequestChanged(android.support.v7.media.MediaRouteDiscoveryRequest)
public void onDiscoveryRequestChanged(@Nullable MediaRouteDiscoveryRequest request)
discovery request
has changed.
Whenever an applications calls MediaRouter.addCallback(android.support.v7.media.MediaRouteSelector, android.support.v7.media.MediaRouter.Callback)
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(android.support.v7.media.MediaRouteDiscoveryRequest)
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.
request
- The new discovery request, or null if no discovery is needed at this time.MediaRouter.addCallback(android.support.v7.media.MediaRouteSelector, android.support.v7.media.MediaRouter.Callback)
@Nullable public final MediaRouteProviderDescriptor getDescriptor()
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(android.support.v7.media.MediaRouteProvider.Callback)
.
MediaRouteProvider.Callback.onDescriptorChanged(android.support.v7.media.MediaRouteProvider, android.support.v7.media.MediaRouteProviderDescriptor)
public final void setDescriptor(@Nullable MediaRouteProviderDescriptor descriptor)
The provider must call this method to notify the currently registered
callback
about the change to the provider's descriptor.
descriptor
- The updated route provider descriptor, or null if none.MediaRouteProvider.Callback.onDescriptorChanged(android.support.v7.media.MediaRouteProvider, android.support.v7.media.MediaRouteProviderDescriptor)
@Nullable public MediaRouteProvider.RouteController onCreateRouteController(@NonNull String routeId)
The media router will invoke the MediaRouteProvider.RouteController.onRelease()
method of the route
controller when it is no longer needed to allow it to free its resources.
routeId
- The unique id of the route.@Nullable public MediaRouteProvider.RouteController onCreateRouteController(@NonNull String routeId, @NonNull String routeGroupId)
MediaRouter.RouteGroup
.
The media router will invoke the MediaRouteProvider.RouteController.onRelease()
method of the route
controller when it is no longer needed to allow it to free its resources.
routeId
- The unique id of the member route.routeGroupId
- The unique id of the route group.