public class RemotePlaybackClient extends Object
MediaControlIntent
.
The client maintains session state and offers a simplified interface for issuing remote playback media control intents to a single route.
Modifier and Type | Class and Description |
---|---|
static class |
RemotePlaybackClient.ActionCallback
Base callback type for remote playback requests.
|
static class |
RemotePlaybackClient.ItemActionCallback
Callback for remote playback requests that operate on items.
|
static interface |
RemotePlaybackClient.OnMessageReceivedListener
A callback that will receive messages from media sessions.
|
static class |
RemotePlaybackClient.SessionActionCallback
Callback for remote playback requests that operate on sessions.
|
static class |
RemotePlaybackClient.StatusCallback
A callback that will receive media status updates.
|
Constructor and Description |
---|
RemotePlaybackClient(Context context,
MediaRouter.RouteInfo route)
Creates a remote playback client for a route.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public RemotePlaybackClient(Context context, MediaRouter.RouteInfo route)
route
- The media route.public void release()
public boolean isRemotePlaybackSupported()
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
.
public boolean isQueuingSupported()
If the route does not support queuing, then at most one media item can be played
at a time and the enqueue(android.net.Uri, java.lang.String, android.os.Bundle, long, android.os.Bundle, android.support.v7.media.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
.
isRemotePlaybackSupported()
is also true.isRemotePlaybackSupported()
public boolean isSessionManagementSupported()
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
.
isRemotePlaybackSupported()
is also true.isRemotePlaybackSupported()
public boolean isMessagingSupported()
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
.
isRemotePlaybackSupported()
is also true.isRemotePlaybackSupported()
public String getSessionId()
public void setSessionId(String sessionId)
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(android.net.Uri, java.lang.String, android.os.Bundle, long, android.os.Bundle, android.support.v7.media.RemotePlaybackClient.ItemActionCallback)
, enqueue(android.net.Uri, java.lang.String, android.os.Bundle, long, android.os.Bundle, android.support.v7.media.RemotePlaybackClient.ItemActionCallback)
, and startSession(android.os.Bundle, android.support.v7.media.RemotePlaybackClient.SessionActionCallback)
.
sessionId
- The new session id, or null if none.public boolean hasSession()
Equivalent to checking whether getSessionId()
returns a non-null result.
public void setStatusCallback(RemotePlaybackClient.StatusCallback callback)
The callback should be set before the session is created or any play commands are issued.
callback
- The callback to set. May be null to remove the previous callback.public void setOnMessageReceivedListener(RemotePlaybackClient.OnMessageReceivedListener listener)
The callback should be set before the session is created.
listener
- The callback to set. May be null to remove the previous callback.public void play(Uri contentUri, String mimeType, Bundle metadata, long positionMillis, Bundle extras, RemotePlaybackClient.ItemActionCallback callback)
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.
contentUri
- The content Uri to play.mimeType
- The mime type of the content, or null if unknown.positionMillis
- The initial content position for the item in milliseconds,
or 0
to start at the beginning.metadata
- The media item metadata bundle, or null if none.extras
- A bundle of extra arguments to be added to the
MediaControlIntent.ACTION_PLAY
intent, or null if none.callback
- A callback to invoke when the request has been
processed, or null if none.UnsupportedOperationException
- if the route does not support remote playback.MediaControlIntent.ACTION_PLAY
,
isRemotePlaybackSupported()
public void enqueue(Uri contentUri, String mimeType, Bundle metadata, long positionMillis, Bundle extras, RemotePlaybackClient.ItemActionCallback callback)
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.
contentUri
- The content Uri to enqueue.mimeType
- The mime type of the content, or null if unknown.positionMillis
- The initial content position for the item in milliseconds,
or 0
to start at the beginning.metadata
- The media item metadata bundle, or null if none.extras
- A bundle of extra arguments to be added to the
MediaControlIntent.ACTION_ENQUEUE
intent, or null if none.callback
- A callback to invoke when the request has been
processed, or null if none.UnsupportedOperationException
- if the route does not support queuing.MediaControlIntent.ACTION_ENQUEUE
,
isRemotePlaybackSupported()
,
isQueuingSupported()
public void seek(String itemId, long positionMillis, Bundle extras, RemotePlaybackClient.ItemActionCallback callback)
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.
itemId
- The item id.positionMillis
- The new content position for the item in milliseconds,
or 0
to start at the beginning.extras
- A bundle of extra arguments to be added to the
MediaControlIntent.ACTION_SEEK
intent, or null if none.callback
- A callback to invoke when the request has been
processed, or null if none.IllegalStateException
- if there is no current session.MediaControlIntent.ACTION_SEEK
,
isRemotePlaybackSupported()
public void getStatus(String itemId, Bundle extras, RemotePlaybackClient.ItemActionCallback callback)
The request is issued in the current session.
Please refer to ACTION_GET_STATUS
for
more information about the semantics of this request.
itemId
- The item id.extras
- A bundle of extra arguments to be added to the
MediaControlIntent.ACTION_GET_STATUS
intent, or null if none.callback
- A callback to invoke when the request has been
processed, or null if none.IllegalStateException
- if there is no current session.MediaControlIntent.ACTION_GET_STATUS
,
isRemotePlaybackSupported()
public void remove(String itemId, Bundle extras, RemotePlaybackClient.ItemActionCallback callback)
The request is issued in the current session.
Please refer to ACTION_REMOVE
for
more information about the semantics of this request.
itemId
- The item id.extras
- A bundle of extra arguments to be added to the
MediaControlIntent.ACTION_REMOVE
intent, or null if none.callback
- A callback to invoke when the request has been
processed, or null if none.IllegalStateException
- if there is no current session.UnsupportedOperationException
- if the route does not support queuing.MediaControlIntent.ACTION_REMOVE
,
isRemotePlaybackSupported()
,
isQueuingSupported()
public void pause(Bundle extras, RemotePlaybackClient.SessionActionCallback callback)
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.
extras
- A bundle of extra arguments to be added to the
MediaControlIntent.ACTION_PAUSE
intent, or null if none.callback
- A callback to invoke when the request has been
processed, or null if none.IllegalStateException
- if there is no current session.MediaControlIntent.ACTION_PAUSE
,
isRemotePlaybackSupported()
public void resume(Bundle extras, RemotePlaybackClient.SessionActionCallback callback)
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.
extras
- A bundle of extra arguments to be added to the
MediaControlIntent.ACTION_RESUME
intent, or null if none.callback
- A callback to invoke when the request has been
processed, or null if none.IllegalStateException
- if there is no current session.MediaControlIntent.ACTION_RESUME
,
isRemotePlaybackSupported()
public void stop(Bundle extras, RemotePlaybackClient.SessionActionCallback callback)
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.
extras
- A bundle of extra arguments to be added to the
MediaControlIntent.ACTION_STOP
intent, or null if none.callback
- A callback to invoke when the request has been
processed, or null if none.IllegalStateException
- if there is no current session.MediaControlIntent.ACTION_STOP
,
isRemotePlaybackSupported()
public void startSession(Bundle extras, RemotePlaybackClient.SessionActionCallback callback)
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.
extras
- A bundle of extra arguments to be added to the
MediaControlIntent.ACTION_START_SESSION
intent, or null if none.callback
- A callback to invoke when the request has been
processed, or null if none.UnsupportedOperationException
- if the route does not support session management.MediaControlIntent.ACTION_START_SESSION
,
isRemotePlaybackSupported()
,
isSessionManagementSupported()
public void sendMessage(Bundle message, RemotePlaybackClient.SessionActionCallback callback)
The request is issued in the current session.
Please refer to MediaControlIntent.ACTION_SEND_MESSAGE
for
more information about the semantics of this request.
message
- A bundle message denoting MediaControlIntent.EXTRA_MESSAGE
.callback
- A callback to invoke when the request has been processed, or null if none.IllegalStateException
- if there is no current session.UnsupportedOperationException
- if the route does not support messages.MediaControlIntent.ACTION_SEND_MESSAGE
,
isMessagingSupported()
public void getSessionStatus(Bundle extras, RemotePlaybackClient.SessionActionCallback callback)
The request is issued in the current session.
Please refer to ACTION_GET_SESSION_STATUS
for more information about the semantics of this request.
extras
- A bundle of extra arguments to be added to the
MediaControlIntent.ACTION_GET_SESSION_STATUS
intent, or null if none.callback
- A callback to invoke when the request has been
processed, or null if none.IllegalStateException
- if there is no current session.UnsupportedOperationException
- if the route does not support session management.MediaControlIntent.ACTION_GET_SESSION_STATUS
,
isRemotePlaybackSupported()
,
isSessionManagementSupported()
public void endSession(Bundle extras, RemotePlaybackClient.SessionActionCallback callback)
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.
extras
- A bundle of extra arguments to be added to the
MediaControlIntent.ACTION_END_SESSION
intent, or null if none.callback
- A callback to invoke when the request has been
processed, or null if none.IllegalStateException
- if there is no current session.UnsupportedOperationException
- if the route does not support session management.MediaControlIntent.ACTION_END_SESSION
,
isRemotePlaybackSupported()
,
isSessionManagementSupported()