FileDocCategorySizeDatePackage
MediaRouteProvider.javaAPI DocAndroid 5.1 API15054Thu Mar 12 22:22:56 GMT 2015android.support.v7.media

MediaRouteProvider

public abstract class MediaRouteProvider extends Object
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 {@link MediaRouteDiscoveryRequest} and publish a {@link MediaRouteProviderDescriptor} with information about each route by calling {@link #setDescriptor} to notify the currently registered {@link Callback}.

The provider should watch for changes to the discovery request by implementing {@link #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 {@link MediaControlIntent media control intents} by implementing {@link #onCreateRouteController} to return a {@link RouteController} for a particular route.

A media route provider may be used privately within the scope of a single application process by calling {@link MediaRouter#addProvider MediaRouter.addProvider} to add it to the local {@link MediaRouter}. A media route provider may also be made available globally to all applications by registering a {@link 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.

Fields Summary
private static final int
MSG_DELIVER_DESCRIPTOR_CHANGED
private static final int
MSG_DELIVER_DISCOVERY_REQUEST_CHANGED
private final android.content.Context
mContext
private final ProviderMetadata
mMetadata
private final ProviderHandler
mHandler
private Callback
mCallback
private MediaRouteDiscoveryRequest
mDiscoveryRequest
private boolean
mPendingDiscoveryRequestChange
private MediaRouteProviderDescriptor
mDescriptor
private boolean
mPendingDescriptorChange
Constructors Summary
public MediaRouteProvider(android.content.Context context)
Creates a media route provider.

param
context The context.


                  
        
        this(context, null);
    
MediaRouteProvider(android.content.Context context, ProviderMetadata metadata)

        if (context == null) {
            throw new IllegalArgumentException("context must not be null");
        }

        mContext = context;
        if (metadata == null) {
            mMetadata = new ProviderMetadata(new ComponentName(context, getClass()));
        } else {
            mMetadata = metadata;
        }
    
Methods Summary
private voiddeliverDescriptorChanged()

        mPendingDescriptorChange = false;

        if (mCallback != null) {
            mCallback.onDescriptorChanged(this, mDescriptor);
        }
    
private voiddeliverDiscoveryRequestChanged()

        mPendingDiscoveryRequestChange = false;
        onDiscoveryRequestChanged(mDiscoveryRequest);
    
public final android.content.ContextgetContext()
Gets the context of the media route provider.

        return mContext;
    
public final MediaRouteProviderDescriptorgetDescriptor()
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 {@link Callback callback} with {@link #setCallback}.

return
The media route provider descriptor, or null if none.
see
Callback#onDescriptorChanged

        return mDescriptor;
    
public final MediaRouteDiscoveryRequestgetDiscoveryRequest()
Gets the current discovery request which informs the provider about the kinds of routes to discover and whether to perform active scanning.

return
The current discovery request, or null if no discovery is needed at this time.
see
#onDiscoveryRequestChanged

        return mDiscoveryRequest;
    
public final android.os.HandlergetHandler()
Gets the provider's handler which is associated with the main thread.

        return mHandler;
    
public final android.support.v7.media.MediaRouteProvider$ProviderMetadatagetMetadata()
Gets some metadata about the provider's implementation.

        return mMetadata;
    
public android.support.v7.media.MediaRouteProvider$RouteControlleronCreateRouteController(java.lang.String routeId)
Called by the media router to obtain a route controller for a particular route.

The media router will invoke the {@link RouteController#onRelease} method of the route controller when it is no longer needed to allow it to free its resources.

param
routeId The unique id of the route.
return
The route controller. Returns null if there is no such route or if the route cannot be controlled using the route controller interface.

        return null;
    
public voidonDiscoveryRequestChanged(MediaRouteDiscoveryRequest request)
Called by the media router when the {@link MediaRouteDiscoveryRequest discovery request} has changed.

Whenever an applications calls {@link MediaRouter#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 {@link MediaRouteDiscoveryRequest} and notifies each provider when a change occurs by calling {@link #setDiscoveryRequest} which posts a message to invoke this method asynchronously.

The provider should examine the {@link MediaControlIntent media control categories} in the discovery request's {@link MediaRouteSelector 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.

param
request The new discovery request, or null if no discovery is needed at this time.
see
MediaRouter#addCallback

    
public final voidsetCallback(android.support.v7.media.MediaRouteProvider$Callback callback)
Sets a callback to invoke when the provider's descriptor changes.

param
callback The callback to use, or null if none.

        MediaRouter.checkCallingThread();
        mCallback = callback;
    
public final voidsetDescriptor(MediaRouteProviderDescriptor descriptor)
Sets the provider's descriptor.

The provider must call this method to notify the currently registered {@link Callback callback} about the change to the provider's descriptor.

param
descriptor The updated route provider descriptor, or null if none.
see
Callback#onDescriptorChanged

        MediaRouter.checkCallingThread();

        if (mDescriptor != descriptor) {
            mDescriptor = descriptor;
            if (!mPendingDescriptorChange) {
                mPendingDescriptorChange = true;
                mHandler.sendEmptyMessage(MSG_DELIVER_DESCRIPTOR_CHANGED);
            }
        }
    
public final voidsetDiscoveryRequest(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.

param
request The discovery request, or null if no discovery is needed at this time.
see
#onDiscoveryRequestChanged

        MediaRouter.checkCallingThread();

        if (mDiscoveryRequest == request
                || (mDiscoveryRequest != null && mDiscoveryRequest.equals(request))) {
            return;
        }

        mDiscoveryRequest = request;
        if (!mPendingDiscoveryRequestChange) {
            mPendingDiscoveryRequestChange = true;
            mHandler.sendEmptyMessage(MSG_DELIVER_DISCOVERY_REQUEST_CHANGED);
        }