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

RemotePlaybackClient

public class RemotePlaybackClient extends Object
A helper class for playing media on remote routes using the remote playback protocol defined by {@link MediaControlIntent}.

The client maintains session state and offers a simplified interface for issuing remote playback media control intents to a single route.

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private final android.content.Context
mContext
private final MediaRouter.RouteInfo
mRoute
private final StatusReceiver
mStatusReceiver
private final android.app.PendingIntent
mItemStatusPendingIntent
private final android.app.PendingIntent
mSessionStatusPendingIntent
private boolean
mRouteSupportsRemotePlayback
private boolean
mRouteSupportsQueuing
private boolean
mRouteSupportsSessionManagement
private String
mSessionId
private StatusCallback
mStatusCallback
Constructors Summary
public RemotePlaybackClient(android.content.Context context, MediaRouter.RouteInfo route)
Creates a remote playback client for a route.

param
route The media route.


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

        mContext = context;
        mRoute = route;

        IntentFilter statusFilter = new IntentFilter();
        statusFilter.addAction(StatusReceiver.ACTION_ITEM_STATUS_CHANGED);
        statusFilter.addAction(StatusReceiver.ACTION_SESSION_STATUS_CHANGED);
        mStatusReceiver = new StatusReceiver();
        context.registerReceiver(mStatusReceiver, statusFilter);

        Intent itemStatusIntent = new Intent(StatusReceiver.ACTION_ITEM_STATUS_CHANGED);
        itemStatusIntent.setPackage(context.getPackageName());
        mItemStatusPendingIntent = PendingIntent.getBroadcast(
                context, 0, itemStatusIntent, 0);

        Intent sessionStatusIntent = new Intent(StatusReceiver.ACTION_SESSION_STATUS_CHANGED);
        sessionStatusIntent.setPackage(context.getPackageName());
        mSessionStatusPendingIntent = PendingIntent.getBroadcast(
                context, 0, sessionStatusIntent, 0);

        detectFeatures();
    
Methods Summary
private voidadoptSession(java.lang.String sessionId)

        if (sessionId != null) {
            setSessionId(sessionId);
        }
    
private static java.lang.StringbundleToString(android.os.Bundle bundle)

        if (bundle != null) {
            bundle.size(); // force bundle to be unparcelled
            return bundle.toString();
        }
        return "null";
    
private voiddetectFeatures()

        mRouteSupportsRemotePlayback = routeSupportsAction(MediaControlIntent.ACTION_PLAY)
                && routeSupportsAction(MediaControlIntent.ACTION_SEEK)
                && routeSupportsAction(MediaControlIntent.ACTION_GET_STATUS)
                && routeSupportsAction(MediaControlIntent.ACTION_PAUSE)
                && routeSupportsAction(MediaControlIntent.ACTION_RESUME)
                && routeSupportsAction(MediaControlIntent.ACTION_STOP);
        mRouteSupportsQueuing = mRouteSupportsRemotePlayback
                && routeSupportsAction(MediaControlIntent.ACTION_ENQUEUE)
                && routeSupportsAction(MediaControlIntent.ACTION_REMOVE);
        mRouteSupportsSessionManagement = mRouteSupportsRemotePlayback
                && routeSupportsAction(MediaControlIntent.ACTION_START_SESSION)
                && routeSupportsAction(MediaControlIntent.ACTION_GET_SESSION_STATUS)
                && routeSupportsAction(MediaControlIntent.ACTION_END_SESSION);
    
public voidendSession(android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$SessionActionCallback callback)
Sends a request to end the media playback session.

The request is issued in the current session. If this request is successful, the {@link #getSessionId session id property} will be set to null after the callback is invoked.

Please refer to {@link MediaControlIntent#ACTION_END_SESSION ACTION_END_SESSION} for more information about the semantics of this request.

param
extras A bundle of extra arguments to be added to the {@link MediaControlIntent#ACTION_END_SESSION} intent, or null if none.
param
callback A callback to invoke when the request has been processed, or null if none.
throws
IllegalStateException if there is no current session.
throws
UnsupportedOperationException if the route does not support session management.
see
MediaControlIntent#ACTION_END_SESSION
see
#isRemotePlaybackSupported
see
#isSessionManagementSupported

        throwIfSessionManagementNotSupported();
        throwIfNoCurrentSession();

        Intent intent = new Intent(MediaControlIntent.ACTION_END_SESSION);
        performSessionAction(intent, mSessionId, extras, callback);
    
public voidenqueue(android.net.Uri contentUri, java.lang.String mimeType, android.os.Bundle metadata, long positionMillis, android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$ItemActionCallback callback)
Sends a request to enqueue a media item.

Enqueues a new item to play. If the queue was previously paused, then will remain paused.

The request is issued in the current session. If no session is available, then one is created implicitly.

Please refer to {@link MediaControlIntent#ACTION_ENQUEUE ACTION_ENQUEUE} for more information about the semantics of this request.

param
contentUri The content Uri to enqueue.
param
mimeType The mime type of the content, or null if unknown.
param
positionMillis The initial content position for the item in milliseconds, or 0 to start at the beginning.
param
metadata The media item metadata bundle, or null if none.
param
extras A bundle of extra arguments to be added to the {@link MediaControlIntent#ACTION_ENQUEUE} intent, or null if none.
param
callback A callback to invoke when the request has been processed, or null if none.
throws
UnsupportedOperationException if the route does not support queuing.
see
MediaControlIntent#ACTION_ENQUEUE
see
#isRemotePlaybackSupported
see
#isQueuingSupported

        playOrEnqueue(contentUri, mimeType, metadata, positionMillis,
                extras, callback, MediaControlIntent.ACTION_ENQUEUE);
    
public java.lang.StringgetSessionId()
Gets the current session id if there is one.

return
The current session id, or null if none.

        return mSessionId;
    
public voidgetSessionStatus(android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$SessionActionCallback callback)
Sends a request to get the status of the media playback session.

The request is issued in the current session.

Please refer to {@link MediaControlIntent#ACTION_GET_SESSION_STATUS ACTION_GET_SESSION_STATUS} for more information about the semantics of this request.

param
extras A bundle of extra arguments to be added to the {@link MediaControlIntent#ACTION_GET_SESSION_STATUS} intent, or null if none.
param
callback A callback to invoke when the request has been processed, or null if none.
throws
IllegalStateException if there is no current session.
throws
UnsupportedOperationException if the route does not support session management.
see
MediaControlIntent#ACTION_GET_SESSION_STATUS
see
#isRemotePlaybackSupported
see
#isSessionManagementSupported

        throwIfSessionManagementNotSupported();
        throwIfNoCurrentSession();

        Intent intent = new Intent(MediaControlIntent.ACTION_GET_SESSION_STATUS);
        performSessionAction(intent, mSessionId, extras, callback);
    
public voidgetStatus(java.lang.String itemId, android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$ItemActionCallback callback)
Sends a request to get the status of a media item.

The request is issued in the current session.

Please refer to {@link MediaControlIntent#ACTION_GET_STATUS ACTION_GET_STATUS} for more information about the semantics of this request.

param
itemId The item id.
param
extras A bundle of extra arguments to be added to the {@link MediaControlIntent#ACTION_GET_STATUS} intent, or null if none.
param
callback A callback to invoke when the request has been processed, or null if none.
throws
IllegalStateException if there is no current session.
see
MediaControlIntent#ACTION_GET_STATUS
see
#isRemotePlaybackSupported

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

        Intent intent = new Intent(MediaControlIntent.ACTION_GET_STATUS);
        performItemAction(intent, mSessionId, itemId, extras, callback);
    
private voidhandleError(android.content.Intent intent, android.support.v7.media.RemotePlaybackClient$ActionCallback callback, java.lang.String error, android.os.Bundle data)

        final int code;
        if (data != null) {
            code = data.getInt(MediaControlIntent.EXTRA_ERROR_CODE,
                    MediaControlIntent.ERROR_UNKNOWN);
        } else {
            code = MediaControlIntent.ERROR_UNKNOWN;
        }
        if (DEBUG) {
            Log.w(TAG, "Received error from " + intent.getAction()
                    + ": error=" + error
                    + ", code=" + code
                    + ", data=" + bundleToString(data));
        }
        callback.onError(error, code, data);
    
private voidhandleInvalidResult(android.content.Intent intent, android.support.v7.media.RemotePlaybackClient$ActionCallback callback, android.os.Bundle data)

        Log.w(TAG, "Received invalid result data from " + intent.getAction()
                + ": data=" + bundleToString(data));
        callback.onError(null, MediaControlIntent.ERROR_UNKNOWN, data);
    
public booleanhasSession()
Returns true if the client currently has a session.

Equivalent to checking whether {@link #getSessionId} returns a non-null result.

return
True if there is a current session.

        return mSessionId != null;
    
private static java.lang.StringinferMissingResult(java.lang.String request, java.lang.String result)

        if (result == null) {
            // Result is missing.
            return request;
        }
        if (request == null || request.equals(result)) {
            // Request didn't specify a value or result matches request.
            return result;
        }
        // Result conflicts with request.
        return null;
    
public booleanisQueuingSupported()
Returns true if the route supports queuing features.

If the route does not support queuing, then at most one media item can be played at a time and the {@link #enqueue} method will not be available.

This method returns true if the route supports all of the basic remote playback actions and all of the following actions: {@link MediaControlIntent#ACTION_ENQUEUE enqueue}, {@link MediaControlIntent#ACTION_REMOVE remove}.

return
True if queuing is supported. Implies {@link #isRemotePlaybackSupported} is also true.
see
#isRemotePlaybackSupported

        return mRouteSupportsQueuing;
    
public booleanisRemotePlaybackSupported()
Returns true if the route supports remote playback.

If the route does not support remote playback, then none of the functionality offered by the client will be available.

This method returns true if the route supports all of the following actions: {@link MediaControlIntent#ACTION_PLAY play}, {@link MediaControlIntent#ACTION_SEEK seek}, {@link MediaControlIntent#ACTION_GET_STATUS get status}, {@link MediaControlIntent#ACTION_PAUSE pause}, {@link MediaControlIntent#ACTION_RESUME resume}, {@link MediaControlIntent#ACTION_STOP stop}.

return
True if remote playback is supported.

        return mRouteSupportsRemotePlayback;
    
public booleanisSessionManagementSupported()
Returns true if the route supports session management features.

If the route does not support session management, then the session will not be created until the first media item is played.

This method returns true if the route supports all of the basic remote playback actions and all of the following actions: {@link MediaControlIntent#ACTION_START_SESSION start session}, {@link MediaControlIntent#ACTION_GET_SESSION_STATUS get session status}, {@link MediaControlIntent#ACTION_END_SESSION end session}.

return
True if session management is supported. Implies {@link #isRemotePlaybackSupported} is also true.
see
#isRemotePlaybackSupported

        return mRouteSupportsSessionManagement;
    
private static voidlogRequest(android.content.Intent intent)

        if (DEBUG) {
            Log.d(TAG, "Sending request: " + intent);
        }
    
public voidpause(android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$SessionActionCallback callback)
Sends a request to pause media playback.

The request is issued in the current session. If playback is already paused then the request has no effect.

Please refer to {@link MediaControlIntent#ACTION_PAUSE ACTION_PAUSE} for more information about the semantics of this request.

param
extras A bundle of extra arguments to be added to the {@link MediaControlIntent#ACTION_PAUSE} intent, or null if none.
param
callback A callback to invoke when the request has been processed, or null if none.
throws
IllegalStateException if there is no current session.
see
MediaControlIntent#ACTION_PAUSE
see
#isRemotePlaybackSupported

        throwIfNoCurrentSession();

        Intent intent = new Intent(MediaControlIntent.ACTION_PAUSE);
        performSessionAction(intent, mSessionId, extras, callback);
    
private voidperformItemAction(android.content.Intent intent, java.lang.String sessionId, java.lang.String itemId, android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$ItemActionCallback callback)

        intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
        if (sessionId != null) {
            intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId);
        }
        if (itemId != null) {
            intent.putExtra(MediaControlIntent.EXTRA_ITEM_ID, itemId);
        }
        if (extras != null) {
            intent.putExtras(extras);
        }
        logRequest(intent);
        mRoute.sendControlRequest(intent, new MediaRouter.ControlRequestCallback() {
            @Override
            public void onResult(Bundle data) {
                if (data != null) {
                    String sessionIdResult = inferMissingResult(sessionId,
                            data.getString(MediaControlIntent.EXTRA_SESSION_ID));
                    MediaSessionStatus sessionStatus = MediaSessionStatus.fromBundle(
                            data.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS));
                    String itemIdResult = inferMissingResult(itemId,
                            data.getString(MediaControlIntent.EXTRA_ITEM_ID));
                    MediaItemStatus itemStatus = MediaItemStatus.fromBundle(
                            data.getBundle(MediaControlIntent.EXTRA_ITEM_STATUS));
                    adoptSession(sessionIdResult);
                    if (sessionIdResult != null && itemIdResult != null && itemStatus != null) {
                        if (DEBUG) {
                            Log.d(TAG, "Received result from " + intent.getAction()
                                    + ": data=" + bundleToString(data)
                                    + ", sessionId=" + sessionIdResult
                                    + ", sessionStatus=" + sessionStatus
                                    + ", itemId=" + itemIdResult
                                    + ", itemStatus=" + itemStatus);
                        }
                        callback.onResult(data, sessionIdResult, sessionStatus,
                                itemIdResult, itemStatus);
                        return;
                    }
                }
                handleInvalidResult(intent, callback, data);
            }

            @Override
            public void onError(String error, Bundle data) {
                handleError(intent, callback, error, data);
            }
        });
    
private voidperformSessionAction(android.content.Intent intent, java.lang.String sessionId, android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$SessionActionCallback callback)

        intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
        if (sessionId != null) {
            intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId);
        }
        if (extras != null) {
            intent.putExtras(extras);
        }
        logRequest(intent);
        mRoute.sendControlRequest(intent, new MediaRouter.ControlRequestCallback() {
            @Override
            public void onResult(Bundle data) {
                if (data != null) {
                    String sessionIdResult = inferMissingResult(sessionId,
                            data.getString(MediaControlIntent.EXTRA_SESSION_ID));
                    MediaSessionStatus sessionStatus = MediaSessionStatus.fromBundle(
                            data.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS));
                    adoptSession(sessionIdResult);
                    if (sessionIdResult != null) {
                        if (DEBUG) {
                            Log.d(TAG, "Received result from " + intent.getAction()
                                    + ": data=" + bundleToString(data)
                                    + ", sessionId=" + sessionIdResult
                                    + ", sessionStatus=" + sessionStatus);
                        }
                        try {
                            callback.onResult(data, sessionIdResult, sessionStatus);
                        } finally {
                            if (intent.getAction().equals(MediaControlIntent.ACTION_END_SESSION)
                                    && sessionIdResult.equals(mSessionId)) {
                                setSessionId(null);
                            }
                        }
                        return;
                    }
                }
                handleInvalidResult(intent, callback, data);
            }

            @Override
            public void onError(String error, Bundle data) {
                handleError(intent, callback, error, data);
            }
        });
    
public voidplay(android.net.Uri contentUri, java.lang.String mimeType, android.os.Bundle metadata, long positionMillis, android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$ItemActionCallback callback)
Sends a request to play a media item.

Clears the queue and starts playing the new item immediately. If the queue was previously paused, then it is resumed as a side-effect of this request.

The request is issued in the current session. If no session is available, then one is created implicitly.

Please refer to {@link MediaControlIntent#ACTION_PLAY ACTION_PLAY} for more information about the semantics of this request.

param
contentUri The content Uri to play.
param
mimeType The mime type of the content, or null if unknown.
param
positionMillis The initial content position for the item in milliseconds, or 0 to start at the beginning.
param
metadata The media item metadata bundle, or null if none.
param
extras A bundle of extra arguments to be added to the {@link MediaControlIntent#ACTION_PLAY} intent, or null if none.
param
callback A callback to invoke when the request has been processed, or null if none.
throws
UnsupportedOperationException if the route does not support remote playback.
see
MediaControlIntent#ACTION_PLAY
see
#isRemotePlaybackSupported

        playOrEnqueue(contentUri, mimeType, metadata, positionMillis,
                extras, callback, MediaControlIntent.ACTION_PLAY);
    
private voidplayOrEnqueue(android.net.Uri contentUri, java.lang.String mimeType, android.os.Bundle metadata, long positionMillis, android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$ItemActionCallback callback, java.lang.String action)

        if (contentUri == null) {
            throw new IllegalArgumentException("contentUri must not be null");
        }
        throwIfRemotePlaybackNotSupported();
        if (action.equals(MediaControlIntent.ACTION_ENQUEUE)) {
            throwIfQueuingNotSupported();
        }

        Intent intent = new Intent(action);
        intent.setDataAndType(contentUri, mimeType);
        intent.putExtra(MediaControlIntent.EXTRA_ITEM_STATUS_UPDATE_RECEIVER,
                mItemStatusPendingIntent);
        if (metadata != null) {
            intent.putExtra(MediaControlIntent.EXTRA_ITEM_METADATA, metadata);
        }
        if (positionMillis != 0) {
            intent.putExtra(MediaControlIntent.EXTRA_ITEM_CONTENT_POSITION, positionMillis);
        }
        performItemAction(intent, mSessionId, null, extras, callback);
    
public voidrelease()
Releases resources owned by the client.

        mContext.unregisterReceiver(mStatusReceiver);
    
public voidremove(java.lang.String itemId, android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$ItemActionCallback callback)
Sends a request to remove a media item from the queue.

The request is issued in the current session.

Please refer to {@link MediaControlIntent#ACTION_REMOVE ACTION_REMOVE} for more information about the semantics of this request.

param
itemId The item id.
param
extras A bundle of extra arguments to be added to the {@link MediaControlIntent#ACTION_REMOVE} intent, or null if none.
param
callback A callback to invoke when the request has been processed, or null if none.
throws
IllegalStateException if there is no current session.
throws
UnsupportedOperationException if the route does not support queuing.
see
MediaControlIntent#ACTION_REMOVE
see
#isRemotePlaybackSupported
see
#isQueuingSupported

        if (itemId == null) {
            throw new IllegalArgumentException("itemId must not be null");
        }
        throwIfQueuingNotSupported();
        throwIfNoCurrentSession();

        Intent intent = new Intent(MediaControlIntent.ACTION_REMOVE);
        performItemAction(intent, mSessionId, itemId, extras, callback);
    
public voidresume(android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$SessionActionCallback callback)
Sends a request to resume (unpause) media playback.

The request is issued in the current session. If playback is not paused then the request has no effect.

Please refer to {@link MediaControlIntent#ACTION_RESUME ACTION_RESUME} for more information about the semantics of this request.

param
extras A bundle of extra arguments to be added to the {@link MediaControlIntent#ACTION_RESUME} intent, or null if none.
param
callback A callback to invoke when the request has been processed, or null if none.
throws
IllegalStateException if there is no current session.
see
MediaControlIntent#ACTION_RESUME
see
#isRemotePlaybackSupported

        throwIfNoCurrentSession();

        Intent intent = new Intent(MediaControlIntent.ACTION_RESUME);
        performSessionAction(intent, mSessionId, extras, callback);
    
private booleanrouteSupportsAction(java.lang.String action)

        return mRoute.supportsControlAction(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK, action);
    
public voidseek(java.lang.String itemId, long positionMillis, android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$ItemActionCallback callback)
Sends a request to seek to a new position in a media item.

Seeks to a new position. If the queue was previously paused then it remains paused but the item's new position is still remembered.

The request is issued in the current session.

Please refer to {@link MediaControlIntent#ACTION_SEEK ACTION_SEEK} for more information about the semantics of this request.

param
itemId The item id.
param
positionMillis The new content position for the item in milliseconds, or 0 to start at the beginning.
param
extras A bundle of extra arguments to be added to the {@link MediaControlIntent#ACTION_SEEK} intent, or null if none.
param
callback A callback to invoke when the request has been processed, or null if none.
throws
IllegalStateException if there is no current session.
see
MediaControlIntent#ACTION_SEEK
see
#isRemotePlaybackSupported

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

        Intent intent = new Intent(MediaControlIntent.ACTION_SEEK);
        intent.putExtra(MediaControlIntent.EXTRA_ITEM_CONTENT_POSITION, positionMillis);
        performItemAction(intent, mSessionId, itemId, extras, callback);
    
public voidsetSessionId(java.lang.String sessionId)
Sets the current session id.

It is usually not necessary to set the session id explicitly since it is created as a side-effect of other requests such as {@link #play}, {@link #enqueue}, and {@link #startSession}.

param
sessionId The new session id, or null if none.

        if (mSessionId != sessionId
                && (mSessionId == null || !mSessionId.equals(sessionId))) {
            if (DEBUG) {
                Log.d(TAG, "Session id is now: " + sessionId);
            }
            mSessionId = sessionId;
            if (mStatusCallback != null) {
                mStatusCallback.onSessionChanged(sessionId);
            }
        }
    
public voidsetStatusCallback(android.support.v7.media.RemotePlaybackClient$StatusCallback callback)
Sets a callback that should receive status updates when the state of media sessions or media items created by this instance of the remote playback client changes.

The callback should be set before the session is created or any play commands are issued.

param
callback The callback to set. May be null to remove the previous callback.

        mStatusCallback = callback;
    
public voidstartSession(android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$SessionActionCallback callback)
Sends a request to start a new media playback session.

The application must wait for the callback to indicate that this request is complete before issuing other requests that affect the session. If this request is successful then the previous session will be invalidated.

Please refer to {@link MediaControlIntent#ACTION_START_SESSION ACTION_START_SESSION} for more information about the semantics of this request.

param
extras A bundle of extra arguments to be added to the {@link MediaControlIntent#ACTION_START_SESSION} intent, or null if none.
param
callback A callback to invoke when the request has been processed, or null if none.
throws
UnsupportedOperationException if the route does not support session management.
see
MediaControlIntent#ACTION_START_SESSION
see
#isRemotePlaybackSupported
see
#isSessionManagementSupported

        throwIfSessionManagementNotSupported();

        Intent intent = new Intent(MediaControlIntent.ACTION_START_SESSION);
        intent.putExtra(MediaControlIntent.EXTRA_SESSION_STATUS_UPDATE_RECEIVER,
                mSessionStatusPendingIntent);
        performSessionAction(intent, null, extras, callback);
    
public voidstop(android.os.Bundle extras, android.support.v7.media.RemotePlaybackClient$SessionActionCallback callback)
Sends a request to stop media playback and clear the media playback queue.

The request is issued in the current session. If the queue is already empty then the request has no effect.

Please refer to {@link MediaControlIntent#ACTION_STOP ACTION_STOP} for more information about the semantics of this request.

param
extras A bundle of extra arguments to be added to the {@link MediaControlIntent#ACTION_STOP} intent, or null if none.
param
callback A callback to invoke when the request has been processed, or null if none.
throws
IllegalStateException if there is no current session.
see
MediaControlIntent#ACTION_STOP
see
#isRemotePlaybackSupported

        throwIfNoCurrentSession();

        Intent intent = new Intent(MediaControlIntent.ACTION_STOP);
        performSessionAction(intent, mSessionId, extras, callback);
    
private voidthrowIfNoCurrentSession()

        if (mSessionId == null) {
            throw new IllegalStateException("There is no current session.");
        }
    
private voidthrowIfQueuingNotSupported()

        if (!mRouteSupportsQueuing) {
            throw new UnsupportedOperationException("The route does not support queuing.");
        }
    
private voidthrowIfRemotePlaybackNotSupported()

        if (!mRouteSupportsRemotePlayback) {
            throw new UnsupportedOperationException("The route does not support remote playback.");
        }
    
private voidthrowIfSessionManagementNotSupported()

        if (!mRouteSupportsSessionManagement) {
            throw new UnsupportedOperationException("The route does not support "
                    + "session management.");
        }