RemotePlaybackClient
class 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 types |
|---|
abstract class RemotePlaybackClient.ActionCallbackBase callback type for remote playback requests. |
|
Callback for remote playback requests that operate on items. |
|
A callback that will receive messages from media sessions. |
|
Callback for remote playback requests that operate on sessions. |
abstract class RemotePlaybackClient.StatusCallbackA callback that will receive media status updates. |
Public constructors |
|---|
RemotePlaybackClient(context: Context, route: MediaRouter.RouteInfo)Creates a remote playback client for a route. |
Public functions |
|
|---|---|
Unit |
endSession(Sends a request to end the media playback session. |
Unit |
enqueue(Sends a request to enqueue a media item. |
String? |
Gets the current session id if there is one. |
Unit |
getSessionStatus(Sends a request to get the status of the media playback session. |
Unit |
getStatus(Sends a request to get the status of a media item. |
Boolean |
Returns true if the client currently has a session. |
Boolean |
Returns true if the route supports messages. |
Boolean |
Returns true if the route supports queuing features. |
Boolean |
Returns true if the route supports remote playback. |
Boolean |
Returns true if the route supports session management features. |
Unit |
pause(Sends a request to pause media playback. |
Unit |
play(Sends a request to play a media item. |
Unit |
release()Releases resources owned by the client. |
Unit |
remove(Sends a request to remove a media item from the queue. |
Unit |
resume(Sends a request to resume (unpause) media playback. |
Unit |
seek(Sends a request to seek to a new position in a media item. |
Unit |
sendMessage(Sends a message. |
Unit |
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. |
Unit |
setSessionId(sessionId: String?)Sets the current session id. |
Unit |
setStatusCallback(callback: RemotePlaybackClient.StatusCallback?)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. |
Unit |
startSession(Sends a request to start a new media playback session. |
Unit |
stop(Sends a request to stop media playback and clear the media playback queue. |
Public constructors
RemotePlaybackClient
RemotePlaybackClient(context: Context, route: MediaRouter.RouteInfo)
Creates a remote playback client for a route.
| Parameters | |
|---|---|
context: Context |
The |
route: MediaRouter.RouteInfo |
The media route. |
Public functions
endSession
fun endSession(
extras: Bundle?,
callback: RemotePlaybackClient.SessionActionCallback?
): Unit
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 |
callback: RemotePlaybackClient.SessionActionCallback? |
A callback to invoke when the request has been processed, or null if none. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if there is no current session. |
java.lang.UnsupportedOperationException |
if the route does not support session management. |
enqueue
fun enqueue(
contentUri: Uri,
mimeType: String?,
metadata: Bundle?,
positionMillis: Long,
extras: Bundle?,
callback: RemotePlaybackClient.ItemActionCallback?
): Unit
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 |
extras: Bundle? |
A bundle of extra arguments to be added to the |
callback: RemotePlaybackClient.ItemActionCallback? |
A callback to invoke when the request has been processed, or null if none. |
| Throws | |
|---|---|
java.lang.UnsupportedOperationException |
if the route does not support queuing. |
getSessionId
fun getSessionId(): String?
Gets the current session id if there is one.
| Returns | |
|---|---|
String? |
The current session id, or null if none. |
getSessionStatus
fun getSessionStatus(
extras: Bundle?,
callback: RemotePlaybackClient.SessionActionCallback?
): Unit
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 |
callback: RemotePlaybackClient.SessionActionCallback? |
A callback to invoke when the request has been processed, or null if none. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if there is no current session. |
java.lang.UnsupportedOperationException |
if the route does not support session management. |
getStatus
fun getStatus(
itemId: String,
extras: Bundle?,
callback: RemotePlaybackClient.ItemActionCallback?
): Unit
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 |
callback: RemotePlaybackClient.ItemActionCallback? |
A callback to invoke when the request has been processed, or null if none. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if there is no current session. |
hasSession
fun hasSession(): Boolean
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
fun isMessagingSupported(): Boolean
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 |
| See also | |
|---|---|
isRemotePlaybackSupported |
isQueuingSupported
fun isQueuingSupported(): Boolean
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 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.
| Returns | |
|---|---|
Boolean |
True if queuing is supported. Implies |
| See also | |
|---|---|
isRemotePlaybackSupported |
isRemotePlaybackSupported
fun isRemotePlaybackSupported(): Boolean
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: play, seek, get status, pause, resume, stop.
| Returns | |
|---|---|
Boolean |
True if remote playback is supported. |
isSessionManagementSupported
fun isSessionManagementSupported(): Boolean
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: start session, get session status, end session.
| Returns | |
|---|---|
Boolean |
True if session management is supported. Implies |
| See also | |
|---|---|
isRemotePlaybackSupported |
pause
fun pause(
extras: Bundle?,
callback: RemotePlaybackClient.SessionActionCallback?
): Unit
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 ACTION_PAUSE for more information about the semantics of this request.
| Parameters | |
|---|---|
extras: Bundle? |
A bundle of extra arguments to be added to the |
callback: RemotePlaybackClient.SessionActionCallback? |
A callback to invoke when the request has been processed, or null if none. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if there is no current session. |
| See also | |
|---|---|
ACTION_PAUSE |
|
isRemotePlaybackSupported |
play
fun play(
contentUri: Uri,
mimeType: String?,
metadata: Bundle?,
positionMillis: Long,
extras: Bundle?,
callback: RemotePlaybackClient.ItemActionCallback?
): Unit
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 ACTION_PLAY for more information about the semantics of this request.
| Parameters | |
|---|---|
contentUri: Uri |
The content Uri to play. |
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 |
extras: Bundle? |
A bundle of extra arguments to be added to the |
callback: RemotePlaybackClient.ItemActionCallback? |
A callback to invoke when the request has been processed, or null if none. |
| Throws | |
|---|---|
java.lang.UnsupportedOperationException |
if the route does not support remote playback. |
| See also | |
|---|---|
ACTION_PLAY |
|
isRemotePlaybackSupported |
remove
fun remove(
itemId: String,
extras: Bundle?,
callback: RemotePlaybackClient.ItemActionCallback?
): Unit
Sends a request to remove a media item from the queue.
The request is issued in the current session.
Please refer to ACTION_REMOVE 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 |
callback: RemotePlaybackClient.ItemActionCallback? |
A callback to invoke when the request has been processed, or null if none. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if there is no current session. |
java.lang.UnsupportedOperationException |
if the route does not support queuing. |
resume
fun resume(
extras: Bundle?,
callback: RemotePlaybackClient.SessionActionCallback?
): Unit
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 ACTION_RESUME for more information about the semantics of this request.
| Parameters | |
|---|---|
extras: Bundle? |
A bundle of extra arguments to be added to the |
callback: RemotePlaybackClient.SessionActionCallback? |
A callback to invoke when the request has been processed, or null if none. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if there is no current session. |
| See also | |
|---|---|
ACTION_RESUME |
|
isRemotePlaybackSupported |
seek
fun seek(
itemId: String,
positionMillis: Long,
extras: Bundle?,
callback: RemotePlaybackClient.ItemActionCallback?
): Unit
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 ACTION_SEEK for more information about the semantics of this request.
| Parameters | |
|---|---|
itemId: String |
The item id. |
positionMillis: Long |
The new content position for the item in milliseconds, or |
extras: Bundle? |
A bundle of extra arguments to be added to the |
callback: RemotePlaybackClient.ItemActionCallback? |
A callback to invoke when the request has been processed, or null if none. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if there is no current session. |
| See also | |
|---|---|
ACTION_SEEK |
|
isRemotePlaybackSupported |
sendMessage
fun sendMessage(
message: Bundle?,
callback: RemotePlaybackClient.SessionActionCallback?
): Unit
Sends a message.
The request is issued in the current session.
Please refer to ACTION_SEND_MESSAGE for more information about the semantics of this request.
| Parameters | |
|---|---|
message: Bundle? |
A bundle message denoting |
callback: RemotePlaybackClient.SessionActionCallback? |
A callback to invoke when the request has been processed, or null if none. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if there is no current session. |
java.lang.UnsupportedOperationException |
if the route does not support messages. |
| See also | |
|---|---|
ACTION_SEND_MESSAGE |
|
isMessagingSupported |
setOnMessageReceivedListener
fun setOnMessageReceivedListener(
listener: RemotePlaybackClient.OnMessageReceivedListener?
): Unit
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.
The callback should be set before the session is created.
| Parameters | |
|---|---|
listener: RemotePlaybackClient.OnMessageReceivedListener? |
The callback to set. May be null to remove the previous callback. |
setSessionId
fun setSessionId(sessionId: String?): Unit
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 play, enqueue, and startSession.
| Parameters | |
|---|---|
sessionId: String? |
The new session id, or null if none. |
setStatusCallback
fun setStatusCallback(callback: RemotePlaybackClient.StatusCallback?): Unit
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.
| Parameters | |
|---|---|
callback: RemotePlaybackClient.StatusCallback? |
The callback to set. May be null to remove the previous callback. |
startSession
fun startSession(
extras: Bundle?,
callback: RemotePlaybackClient.SessionActionCallback?
): Unit
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 ACTION_START_SESSION for more information about the semantics of this request.
| Parameters | |
|---|---|
extras: Bundle? |
A bundle of extra arguments to be added to the |
callback: RemotePlaybackClient.SessionActionCallback? |
A callback to invoke when the request has been processed, or null if none. |
| Throws | |
|---|---|
java.lang.UnsupportedOperationException |
if the route does not support session management. |
stop
fun stop(
extras: Bundle?,
callback: RemotePlaybackClient.SessionActionCallback?
): Unit
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 ACTION_STOP for more information about the semantics of this request.
| Parameters | |
|---|---|
extras: Bundle? |
A bundle of extra arguments to be added to the |
callback: RemotePlaybackClient.SessionActionCallback? |
A callback to invoke when the request has been processed, or null if none. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if there is no current session. |
| See also | |
|---|---|
ACTION_STOP |
|
isRemotePlaybackSupported |