RemotePlaybackClient

public class RemotePlaybackClient
extends Object

java.lang.Object
   ↳ androidx.mediarouter.media.RemotePlaybackClient


A helper class for playing media on remote routes using the remote playback protocol defined by MediaControlIntent.

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

Summary

Nested classes

class RemotePlaybackClient.ActionCallback

Base callback type for remote playback requests. 

class RemotePlaybackClient.ItemActionCallback

Callback for remote playback requests that operate on items. 

interface RemotePlaybackClient.OnMessageReceivedListener

A callback that will receive messages from media sessions. 

class RemotePlaybackClient.SessionActionCallback

Callback for remote playback requests that operate on sessions. 

class RemotePlaybackClient.StatusCallback

A callback that will receive media status updates. 

Public constructors

RemotePlaybackClient(Context context, MediaRouter.RouteInfo route)

Creates a remote playback client for a route.

Public methods

void endSession(Bundle extras, RemotePlaybackClient.SessionActionCallback callback)

Sends a request to end the media playback session.

void enqueue(Uri contentUri, String mimeType, Bundle metadata, long positionMillis, Bundle extras, RemotePlaybackClient.ItemActionCallback callback)

Sends a request to enqueue a media item.

String getSessionId()

Gets the current session id if there is one.

void getSessionStatus(Bundle extras, RemotePlaybackClient.SessionActionCallback callback)

Sends a request to get the status of the media playback session.

void getStatus(String itemId, Bundle extras, RemotePlaybackClient.ItemActionCallback callback)

Sends a request to get the status of a media item.

boolean hasSession()

Returns true if the client currently has a session.

boolean isMessagingSupported()

Returns true if the route supports messages.

boolean isQueuingSupported()

Returns true if the route supports queuing features.

boolean isRemotePlaybackSupported()

Returns true if the route supports remote playback.

boolean isSessionManagementSupported()

Returns true if the route supports session management features.

void pause(Bundle extras, RemotePlaybackClient.SessionActionCallback callback)

Sends a request to pause media playback.

void play(Uri contentUri, String mimeType, Bundle metadata, long positionMillis, Bundle extras, RemotePlaybackClient.ItemActionCallback callback)

Sends a request to play a media item.

void release()

Releases resources owned by the client.

void remove(String itemId, Bundle extras, RemotePlaybackClient.ItemActionCallback callback)

Sends a request to remove a media item from the queue.

void resume(Bundle extras, RemotePlaybackClient.SessionActionCallback callback)

Sends a request to resume (unpause) media playback.

void seek(String itemId, long positionMillis, Bundle extras, RemotePlaybackClient.ItemActionCallback callback)

Sends a request to seek to a new position in a media item.

void sendMessage(Bundle message, RemotePlaybackClient.SessionActionCallback callback)

Sends a message.

void setOnMessageReceivedListener(RemotePlaybackClient.OnMessageReceivedListener listener)

Sets a callback that should receive messages when a message is sent from media sessions created by this instance of the remote playback client changes.

void setSessionId(String sessionId)

Sets the current session id.

void setStatusCallback(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.

void startSession(Bundle extras, RemotePlaybackClient.SessionActionCallback callback)

Sends a request to start a new media playback session.

void stop(Bundle extras, RemotePlaybackClient.SessionActionCallback callback)

Sends a request to stop media playback and clear the media playback queue.

Inherited methods

Public constructors

RemotePlaybackClient

public RemotePlaybackClient (Context context, 
                MediaRouter.RouteInfo route)

Creates a remote playback client for a route.

Parameters
context Context

route MediaRouter.RouteInfo: The media route.

Public methods

endSession

public void endSession (Bundle extras, 
                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 session id property will be set to null after the callback is invoked.

Please refer to ACTION_END_SESSION for more information about the semantics of this request.

Parameters
extras Bundle: A bundle of extra arguments to be added to the MediaControlIntent.ACTION_END_SESSION intent, or null if none.

callback RemotePlaybackClient.SessionActionCallback: A callback to invoke when the request has been processed, or null if none.

Throws
IllegalStateException if there is no current session.
UnsupportedOperationException if the route does not support session management.

enqueue

public void enqueue (Uri contentUri, 
                String mimeType, 
                Bundle metadata, 
                long positionMillis, 
                Bundle extras, 
                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 ACTION_ENQUEUE for more information about the semantics of this request.

Parameters
contentUri Uri: The content Uri to enqueue.

mimeType String: The mime type of the content, or null if unknown.

metadata Bundle: The media item metadata bundle, or null if none.

positionMillis long: The initial content position for the item in milliseconds, or 0 to start at the beginning.

extras Bundle: A bundle of extra arguments to be added to the MediaControlIntent.ACTION_ENQUEUE intent, or null if none.

callback RemotePlaybackClient.ItemActionCallback: A callback to invoke when the request has been processed, or null if none.

Throws
UnsupportedOperationException if the route does not support queuing.

getSessionId

public String getSessionId ()

Gets the current session id if there is one.

Returns
String The current session id, or null if none.

getSessionStatus

public void getSessionStatus (Bundle extras, 
                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 ACTION_GET_SESSION_STATUS for more information about the semantics of this request.

Parameters
extras Bundle: A bundle of extra arguments to be added to the MediaControlIntent.ACTION_GET_SESSION_STATUS intent, or null if none.

callback RemotePlaybackClient.SessionActionCallback: A callback to invoke when the request has been processed, or null if none.

Throws
IllegalStateException if there is no current session.
UnsupportedOperationException if the route does not support session management.

getStatus

public void getStatus (String itemId, 
                Bundle extras, 
                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 ACTION_GET_STATUS for more information about the semantics of this request.

Parameters
itemId String: The item id.

extras Bundle: A bundle of extra arguments to be added to the MediaControlIntent.ACTION_GET_STATUS intent, or null if none.

callback RemotePlaybackClient.ItemActionCallback: A callback to invoke when the request has been processed, or null if none.

Throws
IllegalStateException if there is no current session.

hasSession

public boolean hasSession ()

Returns true if the client currently has a session.

Equivalent to checking whether getSessionId() returns a non-null result.

Returns
boolean True if there is a current session.

isMessagingSupported

public boolean isMessagingSupported ()

Returns true if the route supports messages.

This method returns true if the route supports all of the basic remote playback actions and all of the following actions: start session, send message, end session.

Returns
boolean True if session management is supported. Implies isRemotePlaybackSupported() is also true.

isQueuingSupported

public boolean isQueuingSupported ()

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 enqueue(Uri, String, Bundle, long, Bundle, RemotePlaybackClient.ItemActionCallback) 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: enqueue, remove.

<