Merge "MediaSession: Add new methods for preparing media content" into nyc-dev am: f3db5743b9
am: e53db46568
* commit 'e53db46568f2a7830e5fe1d8ddd69d8c0dfb89b7':
MediaSession: Add new methods for preparing media content
This commit is contained in:
@@ -22556,6 +22556,10 @@ package android.media.session {
|
||||
method public void playFromMediaId(java.lang.String, android.os.Bundle);
|
||||
method public void playFromSearch(java.lang.String, android.os.Bundle);
|
||||
method public void playFromUri(android.net.Uri, android.os.Bundle);
|
||||
method public void prepare();
|
||||
method public void prepareFromMediaId(java.lang.String, android.os.Bundle);
|
||||
method public void prepareFromSearch(java.lang.String, android.os.Bundle);
|
||||
method public void prepareFromUri(android.net.Uri, android.os.Bundle);
|
||||
method public void rewind();
|
||||
method public void seekTo(long);
|
||||
method public void sendCustomAction(android.media.session.PlaybackState.CustomAction, android.os.Bundle);
|
||||
@@ -22589,7 +22593,6 @@ package android.media.session {
|
||||
method public void setRatingType(int);
|
||||
method public void setSessionActivity(android.app.PendingIntent);
|
||||
field public static final int FLAG_HANDLES_MEDIA_BUTTONS = 1; // 0x1
|
||||
field public static final int FLAG_HANDLES_PREPARE_ONLY = 4; // 0x4
|
||||
field public static final int FLAG_HANDLES_TRANSPORT_CONTROLS = 2; // 0x2
|
||||
}
|
||||
|
||||
@@ -22604,6 +22607,10 @@ package android.media.session {
|
||||
method public void onPlayFromMediaId(java.lang.String, android.os.Bundle);
|
||||
method public void onPlayFromSearch(java.lang.String, android.os.Bundle);
|
||||
method public void onPlayFromUri(android.net.Uri, android.os.Bundle);
|
||||
method public void onPrepare();
|
||||
method public void onPrepareFromMediaId(java.lang.String, android.os.Bundle);
|
||||
method public void onPrepareFromSearch(java.lang.String, android.os.Bundle);
|
||||
method public void onPrepareFromUri(android.net.Uri, android.os.Bundle);
|
||||
method public void onRewind();
|
||||
method public void onSeekTo(long);
|
||||
method public void onSetRating(android.media.Rating);
|
||||
@@ -22660,6 +22667,10 @@ package android.media.session {
|
||||
field public static final long ACTION_PLAY_FROM_SEARCH = 2048L; // 0x800L
|
||||
field public static final long ACTION_PLAY_FROM_URI = 8192L; // 0x2000L
|
||||
field public static final long ACTION_PLAY_PAUSE = 512L; // 0x200L
|
||||
field public static final long ACTION_PREPARE = 16384L; // 0x4000L
|
||||
field public static final long ACTION_PREPARE_FROM_MEDIA_ID = 32768L; // 0x8000L
|
||||
field public static final long ACTION_PREPARE_FROM_SEARCH = 65536L; // 0x10000L
|
||||
field public static final long ACTION_PREPARE_FROM_URI = 131072L; // 0x20000L
|
||||
field public static final long ACTION_REWIND = 8L; // 0x8L
|
||||
field public static final long ACTION_SEEK_TO = 256L; // 0x100L
|
||||
field public static final long ACTION_SET_RATING = 128L; // 0x80L
|
||||
@@ -22668,7 +22679,6 @@ package android.media.session {
|
||||
field public static final long ACTION_SKIP_TO_QUEUE_ITEM = 4096L; // 0x1000L
|
||||
field public static final long ACTION_STOP = 1L; // 0x1L
|
||||
field public static final android.os.Parcelable.Creator<android.media.session.PlaybackState> CREATOR;
|
||||
field public static final java.lang.String EXTRA_PREPARE_ONLY = "android.media.session.extra.PREPARE_ONLY";
|
||||
field public static final long PLAYBACK_POSITION_UNKNOWN = -1L; // 0xffffffffffffffffL
|
||||
field public static final int STATE_BUFFERING = 6; // 0x6
|
||||
field public static final int STATE_CONNECTING = 8; // 0x8
|
||||
|
||||
@@ -24129,6 +24129,10 @@ package android.media.session {
|
||||
method public void playFromMediaId(java.lang.String, android.os.Bundle);
|
||||
method public void playFromSearch(java.lang.String, android.os.Bundle);
|
||||
method public void playFromUri(android.net.Uri, android.os.Bundle);
|
||||
method public void prepare();
|
||||
method public void prepareFromMediaId(java.lang.String, android.os.Bundle);
|
||||
method public void prepareFromSearch(java.lang.String, android.os.Bundle);
|
||||
method public void prepareFromUri(android.net.Uri, android.os.Bundle);
|
||||
method public void rewind();
|
||||
method public void seekTo(long);
|
||||
method public void sendCustomAction(android.media.session.PlaybackState.CustomAction, android.os.Bundle);
|
||||
@@ -24162,7 +24166,6 @@ package android.media.session {
|
||||
method public void setRatingType(int);
|
||||
method public void setSessionActivity(android.app.PendingIntent);
|
||||
field public static final int FLAG_HANDLES_MEDIA_BUTTONS = 1; // 0x1
|
||||
field public static final int FLAG_HANDLES_PREPARE_ONLY = 4; // 0x4
|
||||
field public static final int FLAG_HANDLES_TRANSPORT_CONTROLS = 2; // 0x2
|
||||
}
|
||||
|
||||
@@ -24177,6 +24180,10 @@ package android.media.session {
|
||||
method public void onPlayFromMediaId(java.lang.String, android.os.Bundle);
|
||||
method public void onPlayFromSearch(java.lang.String, android.os.Bundle);
|
||||
method public void onPlayFromUri(android.net.Uri, android.os.Bundle);
|
||||
method public void onPrepare();
|
||||
method public void onPrepareFromMediaId(java.lang.String, android.os.Bundle);
|
||||
method public void onPrepareFromSearch(java.lang.String, android.os.Bundle);
|
||||
method public void onPrepareFromUri(android.net.Uri, android.os.Bundle);
|
||||
method public void onRewind();
|
||||
method public void onSeekTo(long);
|
||||
method public void onSetRating(android.media.Rating);
|
||||
@@ -24233,6 +24240,10 @@ package android.media.session {
|
||||
field public static final long ACTION_PLAY_FROM_SEARCH = 2048L; // 0x800L
|
||||
field public static final long ACTION_PLAY_FROM_URI = 8192L; // 0x2000L
|
||||
field public static final long ACTION_PLAY_PAUSE = 512L; // 0x200L
|
||||
field public static final long ACTION_PREPARE = 16384L; // 0x4000L
|
||||
field public static final long ACTION_PREPARE_FROM_MEDIA_ID = 32768L; // 0x8000L
|
||||
field public static final long ACTION_PREPARE_FROM_SEARCH = 65536L; // 0x10000L
|
||||
field public static final long ACTION_PREPARE_FROM_URI = 131072L; // 0x20000L
|
||||
field public static final long ACTION_REWIND = 8L; // 0x8L
|
||||
field public static final long ACTION_SEEK_TO = 256L; // 0x100L
|
||||
field public static final long ACTION_SET_RATING = 128L; // 0x80L
|
||||
@@ -24241,7 +24252,6 @@ package android.media.session {
|
||||
field public static final long ACTION_SKIP_TO_QUEUE_ITEM = 4096L; // 0x1000L
|
||||
field public static final long ACTION_STOP = 1L; // 0x1L
|
||||
field public static final android.os.Parcelable.Creator<android.media.session.PlaybackState> CREATOR;
|
||||
field public static final java.lang.String EXTRA_PREPARE_ONLY = "android.media.session.extra.PREPARE_ONLY";
|
||||
field public static final long PLAYBACK_POSITION_UNKNOWN = -1L; // 0xffffffffffffffffL
|
||||
field public static final int STATE_BUFFERING = 6; // 0x6
|
||||
field public static final int STATE_CONNECTING = 8; // 0x8
|
||||
|
||||
@@ -22565,6 +22565,10 @@ package android.media.session {
|
||||
method public void playFromMediaId(java.lang.String, android.os.Bundle);
|
||||
method public void playFromSearch(java.lang.String, android.os.Bundle);
|
||||
method public void playFromUri(android.net.Uri, android.os.Bundle);
|
||||
method public void prepare();
|
||||
method public void prepareFromMediaId(java.lang.String, android.os.Bundle);
|
||||
method public void prepareFromSearch(java.lang.String, android.os.Bundle);
|
||||
method public void prepareFromUri(android.net.Uri, android.os.Bundle);
|
||||
method public void rewind();
|
||||
method public void seekTo(long);
|
||||
method public void sendCustomAction(android.media.session.PlaybackState.CustomAction, android.os.Bundle);
|
||||
@@ -22598,7 +22602,6 @@ package android.media.session {
|
||||
method public void setRatingType(int);
|
||||
method public void setSessionActivity(android.app.PendingIntent);
|
||||
field public static final int FLAG_HANDLES_MEDIA_BUTTONS = 1; // 0x1
|
||||
field public static final int FLAG_HANDLES_PREPARE_ONLY = 4; // 0x4
|
||||
field public static final int FLAG_HANDLES_TRANSPORT_CONTROLS = 2; // 0x2
|
||||
}
|
||||
|
||||
@@ -22613,6 +22616,10 @@ package android.media.session {
|
||||
method public void onPlayFromMediaId(java.lang.String, android.os.Bundle);
|
||||
method public void onPlayFromSearch(java.lang.String, android.os.Bundle);
|
||||
method public void onPlayFromUri(android.net.Uri, android.os.Bundle);
|
||||
method public void onPrepare();
|
||||
method public void onPrepareFromMediaId(java.lang.String, android.os.Bundle);
|
||||
method public void onPrepareFromSearch(java.lang.String, android.os.Bundle);
|
||||
method public void onPrepareFromUri(android.net.Uri, android.os.Bundle);
|
||||
method public void onRewind();
|
||||
method public void onSeekTo(long);
|
||||
method public void onSetRating(android.media.Rating);
|
||||
@@ -22669,6 +22676,10 @@ package android.media.session {
|
||||
field public static final long ACTION_PLAY_FROM_SEARCH = 2048L; // 0x800L
|
||||
field public static final long ACTION_PLAY_FROM_URI = 8192L; // 0x2000L
|
||||
field public static final long ACTION_PLAY_PAUSE = 512L; // 0x200L
|
||||
field public static final long ACTION_PREPARE = 16384L; // 0x4000L
|
||||
field public static final long ACTION_PREPARE_FROM_MEDIA_ID = 32768L; // 0x8000L
|
||||
field public static final long ACTION_PREPARE_FROM_SEARCH = 65536L; // 0x10000L
|
||||
field public static final long ACTION_PREPARE_FROM_URI = 131072L; // 0x20000L
|
||||
field public static final long ACTION_REWIND = 8L; // 0x8L
|
||||
field public static final long ACTION_SEEK_TO = 256L; // 0x100L
|
||||
field public static final long ACTION_SET_RATING = 128L; // 0x80L
|
||||
@@ -22677,7 +22688,6 @@ package android.media.session {
|
||||
field public static final long ACTION_SKIP_TO_QUEUE_ITEM = 4096L; // 0x1000L
|
||||
field public static final long ACTION_STOP = 1L; // 0x1L
|
||||
field public static final android.os.Parcelable.Creator<android.media.session.PlaybackState> CREATOR;
|
||||
field public static final java.lang.String EXTRA_PREPARE_ONLY = "android.media.session.extra.PREPARE_ONLY";
|
||||
field public static final long PLAYBACK_POSITION_UNKNOWN = -1L; // 0xffffffffffffffffL
|
||||
field public static final int STATE_BUFFERING = 6; // 0x6
|
||||
field public static final int STATE_CONNECTING = 8; // 0x8
|
||||
|
||||
@@ -29,6 +29,10 @@ oneway interface ISessionCallback {
|
||||
void onMediaButton(in Intent mediaButtonIntent, int sequenceNumber, in ResultReceiver cb);
|
||||
|
||||
// These callbacks are for the TransportPerformer
|
||||
void onPrepare();
|
||||
void onPrepareFromMediaId(String mediaId, in Bundle extras);
|
||||
void onPrepareFromSearch(String query, in Bundle extras);
|
||||
void onPrepareFromUri(in Uri uri, in Bundle extras);
|
||||
void onPlay();
|
||||
void onPlayFromMediaId(String mediaId, in Bundle extras);
|
||||
void onPlayFromSearch(String query, in Bundle extras);
|
||||
|
||||
@@ -50,6 +50,10 @@ interface ISessionController {
|
||||
void setVolumeTo(int value, int flags, String packageName);
|
||||
|
||||
// These commands are for the TransportControls
|
||||
void prepare();
|
||||
void prepareFromMediaId(String mediaId, in Bundle extras);
|
||||
void prepareFromSearch(String string, in Bundle extras);
|
||||
void prepareFromUri(in Uri uri, in Bundle extras);
|
||||
void play();
|
||||
void playFromMediaId(String mediaId, in Bundle extras);
|
||||
void playFromSearch(String string, in Bundle extras);
|
||||
|
||||
@@ -591,6 +591,90 @@ public final class MediaController {
|
||||
private TransportControls() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that the player prepare its playback. Once the preparation is done, the session
|
||||
* will change its playback state to {@link PlaybackState#STATE_PAUSED}. Afterwards,
|
||||
* {@link #play} can be called to start playback. If the preparation is not needed,
|
||||
* {@link #play} can be directly called without this method.
|
||||
*/
|
||||
public void prepare() {
|
||||
try {
|
||||
mSessionBinder.prepare();
|
||||
} catch (RemoteException e) {
|
||||
Log.wtf(TAG, "Error calling prepare.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that the player prepare playback for a specific media id. Once the preparation is
|
||||
* done, the session will change its playback state to {@link PlaybackState#STATE_PAUSED}.
|
||||
* Afterwards, {@link #play} can be called to start playback. If the preparation is not
|
||||
* needed, {@link #playFromMediaId} can be directly called without this method.
|
||||
*
|
||||
* @param mediaId The id of the requested media.
|
||||
* @param extras Optional extras that can include extra information about the media item
|
||||
* to be prepared.
|
||||
*/
|
||||
public void prepareFromMediaId(String mediaId, Bundle extras) {
|
||||
if (TextUtils.isEmpty(mediaId)) {
|
||||
throw new IllegalArgumentException(
|
||||
"You must specify a non-empty String for prepareFromMediaId.");
|
||||
}
|
||||
try {
|
||||
mSessionBinder.prepareFromMediaId(mediaId, extras);
|
||||
} catch (RemoteException e) {
|
||||
Log.wtf(TAG, "Error calling prepare(" + mediaId + ").", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that the player prepare playback for a specific search query.
|
||||
* An empty or null query should be treated as a request to prepare any
|
||||
* music. Once the preparation is done, the session will change its playback state to
|
||||
* {@link PlaybackState#STATE_PAUSED}. Afterwards, {@link #play} can be called to start
|
||||
* playback. If the preparation is not needed, {@link #playFromSearch} can be directly
|
||||
* called without this method.
|
||||
*
|
||||
* @param query The search query.
|
||||
* @param extras Optional extras that can include extra information
|
||||
* about the query.
|
||||
*/
|
||||
public void prepareFromSearch(String query, Bundle extras) {
|
||||
if (query == null) {
|
||||
// This is to remain compatible with
|
||||
// INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH
|
||||
query = "";
|
||||
}
|
||||
try {
|
||||
mSessionBinder.prepareFromSearch(query, extras);
|
||||
} catch (RemoteException e) {
|
||||
Log.wtf(TAG, "Error calling prepare(" + query + ").", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that the player prepare playback for a specific {@link Uri}.
|
||||
* Once the preparation is done, the session will change its playback state to
|
||||
* {@link PlaybackState#STATE_PAUSED}. Afterwards, {@link #play} can be called to start
|
||||
* playback. If the preparation is not needed, {@link #playFromUri} can be directly
|
||||
* called without this method.
|
||||
*
|
||||
* @param uri The URI of the requested media.
|
||||
* @param extras Optional extras that can include extra information about the media item
|
||||
* to be prepared.
|
||||
*/
|
||||
public void prepareFromUri(Uri uri, Bundle extras) {
|
||||
if (uri == null || Uri.EMPTY.equals(uri)) {
|
||||
throw new IllegalArgumentException(
|
||||
"You must specify a non-empty Uri for prepareFromUri.");
|
||||
}
|
||||
try {
|
||||
mSessionBinder.prepareFromUri(uri, extras);
|
||||
} catch (RemoteException e) {
|
||||
Log.wtf(TAG, "Error calling prepare(" + uri + ").", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that the player start its playback at its current position.
|
||||
*/
|
||||
@@ -605,7 +689,6 @@ public final class MediaController {
|
||||
/**
|
||||
* Request that the player start playback for a specific media id.
|
||||
*
|
||||
* @see PlaybackState#EXTRA_PREPARE_ONLY
|
||||
* @param mediaId The id of the requested media.
|
||||
* @param extras Optional extras that can include extra information about the media item
|
||||
* to be played.
|
||||
@@ -627,10 +710,9 @@ public final class MediaController {
|
||||
* An empty or null query should be treated as a request to play any
|
||||
* music.
|
||||
*
|
||||
* @see PlaybackState#EXTRA_PREPARE_ONLY
|
||||
* @param query The search query.
|
||||
* @param extras Optional extras that can include extra information
|
||||
* about the query.
|
||||
* about the query.
|
||||
*/
|
||||
public void playFromSearch(String query, Bundle extras) {
|
||||
if (query == null) {
|
||||
@@ -648,8 +730,7 @@ public final class MediaController {
|
||||
/**
|
||||
* Request that the player start playback for a specific {@link Uri}.
|
||||
*
|
||||
* @see PlaybackState#EXTRA_PREPARE_ONLY
|
||||
* @param uri The URI of the requested media.
|
||||
* @param uri The URI of the requested media.
|
||||
* @param extras Optional extras that can include extra information about the media item
|
||||
* to be played.
|
||||
*/
|
||||
|
||||
@@ -86,12 +86,6 @@ public final class MediaSession {
|
||||
*/
|
||||
public static final int FLAG_HANDLES_TRANSPORT_CONTROLS = 1 << 1;
|
||||
|
||||
/**
|
||||
* Set this flag on the session to indicate that it can handle
|
||||
* the {@link PlaybackState#EXTRA_PREPARE_ONLY} field.
|
||||
*/
|
||||
public static final int FLAG_HANDLES_PREPARE_ONLY = 1 << 2;
|
||||
|
||||
/**
|
||||
* System only flag for a session that needs to have priority over all other
|
||||
* sessions. This flag ensures this session will receive media button events
|
||||
@@ -106,7 +100,6 @@ public final class MediaSession {
|
||||
@IntDef(flag = true, value = {
|
||||
FLAG_HANDLES_MEDIA_BUTTONS,
|
||||
FLAG_HANDLES_TRANSPORT_CONTROLS,
|
||||
FLAG_HANDLES_PREPARE_ONLY,
|
||||
FLAG_EXCLUSIVE_GLOBAL_PRIORITY })
|
||||
public @interface SessionFlags { }
|
||||
|
||||
@@ -519,6 +512,22 @@ public final class MediaSession {
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchPrepare() {
|
||||
postToCallback(CallbackMessageHandler.MSG_PREPARE);
|
||||
}
|
||||
|
||||
private void dispatchPrepareFromMediaId(String mediaId, Bundle extras) {
|
||||
postToCallback(CallbackMessageHandler.MSG_PREPARE_MEDIA_ID, mediaId, extras);
|
||||
}
|
||||
|
||||
private void dispatchPrepareFromSearch(String query, Bundle extras) {
|
||||
postToCallback(CallbackMessageHandler.MSG_PREPARE_SEARCH, query, extras);
|
||||
}
|
||||
|
||||
private void dispatchPrepareFromUri(Uri uri, Bundle extras) {
|
||||
postToCallback(CallbackMessageHandler.MSG_PREPARE_URI, uri, extras);
|
||||
}
|
||||
|
||||
private void dispatchPlay() {
|
||||
postToCallback(CallbackMessageHandler.MSG_PLAY);
|
||||
}
|
||||
@@ -805,16 +814,49 @@ public final class MediaSession {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to handle requests to begin playback.
|
||||
* Override to handle requests to prepare playback. The state of playback should be updated
|
||||
* to {@link PlaybackState#STATE_PAUSED} after the preparation is done. Override
|
||||
* {@link #onPlay} to handle requests for starting playback of prepared content.
|
||||
*/
|
||||
public void onPlay() {
|
||||
public void onPrepare() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to handle requests to play a specific mediaId that was
|
||||
* provided by your app's {@link MediaBrowserService}.
|
||||
* Override to handle requests to prepare for playing a specific mediaId that was provided
|
||||
* by your app's {@link MediaBrowserService}. The state of playback should be updated
|
||||
* to {@link PlaybackState#STATE_PAUSED} after the preparation is done. The playback of
|
||||
* the prepared content should start in the implementation of {@link #onPlay}. Override
|
||||
* {@link #onPlayFromMediaId} to handle requests for starting playback without preparation.
|
||||
*/
|
||||
public void onPlayFromMediaId(String mediaId, Bundle extras) {
|
||||
public void onPrepareFromMediaId(String mediaId, Bundle extras) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to handle requests to prepare playback from a search query. An
|
||||
* empty query indicates that the app may prepare any music. The
|
||||
* implementation should attempt to make a smart choice about what to
|
||||
* play. The state of playback should be updated to {@link PlaybackState#STATE_PAUSED}
|
||||
* after the preparation is done. The playback of the prepared content should start
|
||||
* in the implementation of {@link #onPlay}. Override {@link #onPlayFromSearch}
|
||||
* to handle requests for starting playback without preparation.
|
||||
*/
|
||||
public void onPrepareFromSearch(String query, Bundle extras) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to handle requests to prepare a specific media item represented by a URI.
|
||||
* The state of playback should be updated to {@link PlaybackState#STATE_PAUSED}
|
||||
* after the preparation is done. The playback of the prepared content should start in
|
||||
* the implementation of {@link #onPlay}. Override {@link #onPlayFromUri} to handle requests
|
||||
* for starting playback without preparation.
|
||||
*/
|
||||
public void onPrepareFromUri(Uri uri, Bundle extras) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to handle requests to begin playback.
|
||||
*/
|
||||
public void onPlay() {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -826,6 +868,13 @@ public final class MediaSession {
|
||||
public void onPlayFromSearch(String query, Bundle extras) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to handle requests to play a specific mediaId that was
|
||||
* provided by your app's {@link MediaBrowserService}.
|
||||
*/
|
||||
public void onPlayFromMediaId(String mediaId, Bundle extras) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to handle requests to play a specific media item represented by a URI.
|
||||
*/
|
||||
@@ -936,6 +985,38 @@ public final class MediaSession {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepare() {
|
||||
MediaSession session = mMediaSession.get();
|
||||
if (session != null) {
|
||||
session.dispatchPrepare();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareFromMediaId(String mediaId, Bundle extras) {
|
||||
MediaSession session = mMediaSession.get();
|
||||
if (session != null) {
|
||||
session.dispatchPrepareFromMediaId(mediaId, extras);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareFromSearch(String query, Bundle extras) {
|
||||
MediaSession session = mMediaSession.get();
|
||||
if (session != null) {
|
||||
session.dispatchPrepareFromSearch(query, extras);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareFromUri(Uri uri, Bundle extras) {
|
||||
MediaSession session = mMediaSession.get();
|
||||
if (session != null) {
|
||||
session.dispatchPrepareFromUri(uri, extras);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlay() {
|
||||
MediaSession session = mMediaSession.get();
|
||||
@@ -1162,24 +1243,28 @@ public final class MediaSession {
|
||||
|
||||
private class CallbackMessageHandler extends Handler {
|
||||
|
||||
private static final int MSG_PLAY = 1;
|
||||
private static final int MSG_PLAY_MEDIA_ID = 2;
|
||||
private static final int MSG_PLAY_SEARCH = 3;
|
||||
private static final int MSG_SKIP_TO_ITEM = 4;
|
||||
private static final int MSG_PAUSE = 5;
|
||||
private static final int MSG_STOP = 6;
|
||||
private static final int MSG_NEXT = 7;
|
||||
private static final int MSG_PREVIOUS = 8;
|
||||
private static final int MSG_FAST_FORWARD = 9;
|
||||
private static final int MSG_REWIND = 10;
|
||||
private static final int MSG_SEEK_TO = 11;
|
||||
private static final int MSG_RATE = 12;
|
||||
private static final int MSG_CUSTOM_ACTION = 13;
|
||||
private static final int MSG_MEDIA_BUTTON = 14;
|
||||
private static final int MSG_COMMAND = 15;
|
||||
private static final int MSG_ADJUST_VOLUME = 16;
|
||||
private static final int MSG_SET_VOLUME = 17;
|
||||
private static final int MSG_PLAY_URI = 18;
|
||||
private static final int MSG_COMMAND = 1;
|
||||
private static final int MSG_MEDIA_BUTTON = 2;
|
||||
private static final int MSG_PREPARE = 3;
|
||||
private static final int MSG_PREPARE_MEDIA_ID = 4;
|
||||
private static final int MSG_PREPARE_SEARCH = 5;
|
||||
private static final int MSG_PREPARE_URI = 6;
|
||||
private static final int MSG_PLAY = 7;
|
||||
private static final int MSG_PLAY_MEDIA_ID = 8;
|
||||
private static final int MSG_PLAY_SEARCH = 9;
|
||||
private static final int MSG_PLAY_URI = 10;
|
||||
private static final int MSG_SKIP_TO_ITEM = 11;
|
||||
private static final int MSG_PAUSE = 12;
|
||||
private static final int MSG_STOP = 13;
|
||||
private static final int MSG_NEXT = 14;
|
||||
private static final int MSG_PREVIOUS = 15;
|
||||
private static final int MSG_FAST_FORWARD = 16;
|
||||
private static final int MSG_REWIND = 17;
|
||||
private static final int MSG_SEEK_TO = 18;
|
||||
private static final int MSG_RATE = 19;
|
||||
private static final int MSG_CUSTOM_ACTION = 20;
|
||||
private static final int MSG_ADJUST_VOLUME = 21;
|
||||
private static final int MSG_SET_VOLUME = 22;
|
||||
|
||||
private MediaSession.Callback mCallback;
|
||||
|
||||
@@ -1210,6 +1295,25 @@ public final class MediaSession {
|
||||
public void handleMessage(Message msg) {
|
||||
VolumeProvider vp;
|
||||
switch (msg.what) {
|
||||
case MSG_COMMAND:
|
||||
Command cmd = (Command) msg.obj;
|
||||
mCallback.onCommand(cmd.command, cmd.extras, cmd.stub);
|
||||
break;
|
||||
case MSG_MEDIA_BUTTON:
|
||||
mCallback.onMediaButtonEvent((Intent) msg.obj);
|
||||
break;
|
||||
case MSG_PREPARE:
|
||||
mCallback.onPrepare();
|
||||
break;
|
||||
case MSG_PREPARE_MEDIA_ID:
|
||||
mCallback.onPrepareFromMediaId((String) msg.obj, msg.getData());
|
||||
break;
|
||||
case MSG_PREPARE_SEARCH:
|
||||
mCallback.onPrepareFromSearch((String) msg.obj, msg.getData());
|
||||
break;
|
||||
case MSG_PREPARE_URI:
|
||||
mCallback.onPrepareFromUri((Uri) msg.obj, msg.getData());
|
||||
break;
|
||||
case MSG_PLAY:
|
||||
mCallback.onPlay();
|
||||
break;
|
||||
@@ -1252,13 +1356,6 @@ public final class MediaSession {
|
||||
case MSG_CUSTOM_ACTION:
|
||||
mCallback.onCustomAction((String) msg.obj, msg.getData());
|
||||
break;
|
||||
case MSG_MEDIA_BUTTON:
|
||||
mCallback.onMediaButtonEvent((Intent) msg.obj);
|
||||
break;
|
||||
case MSG_COMMAND:
|
||||
Command cmd = (Command) msg.obj;
|
||||
mCallback.onCommand(cmd.command, cmd.extras, cmd.stub);
|
||||
break;
|
||||
case MSG_ADJUST_VOLUME:
|
||||
synchronized (mLock) {
|
||||
vp = mVolumeProvider;
|
||||
|
||||
@@ -133,19 +133,32 @@ public final class PlaybackState implements Parcelable {
|
||||
public static final long ACTION_PLAY_FROM_URI = 1 << 13;
|
||||
|
||||
/**
|
||||
* Used as an optional boolean extra field in
|
||||
* {@link MediaController.TransportControls#playFromMediaId},
|
||||
* {@link MediaController.TransportControls#playFromSearch}, and
|
||||
* {@link MediaController.TransportControls#playFromUri}. Value of {@code true} overrides
|
||||
* the default behavior of starting the playback after preparing. Check
|
||||
* {@link MediaSession#FLAG_HANDLES_PREPARE_ONLY} to see if the media session supports this.
|
||||
* Indicates this session supports the prepare command.
|
||||
*
|
||||
* @see MediaSession#FLAG_HANDLES_PREPARE_ONLY
|
||||
* @see MediaController.TransportControls#playFromMediaId
|
||||
* @see MediaController.TransportControls#playFromSearch
|
||||
* @see MediaController.TransportControls#playFromUri
|
||||
* @see Builder#setActions(long)
|
||||
*/
|
||||
public static final String EXTRA_PREPARE_ONLY = "android.media.session.extra.PREPARE_ONLY";
|
||||
public static final long ACTION_PREPARE = 1 << 14;
|
||||
|
||||
/**
|
||||
* Indicates this session supports the prepare from media id command.
|
||||
*
|
||||
* @see Builder#setActions(long)
|
||||
*/
|
||||
public static final long ACTION_PREPARE_FROM_MEDIA_ID = 1 << 15;
|
||||
|
||||
/**
|
||||
* Indicates this session supports the prepare from search command.
|
||||
*
|
||||
* @see Builder#setActions(long)
|
||||
*/
|
||||
public static final long ACTION_PREPARE_FROM_SEARCH = 1 << 16;
|
||||
|
||||
/**
|
||||
* Indicates this session supports the prepare from URI command.
|
||||
*
|
||||
* @see Builder#setActions(long)
|
||||
*/
|
||||
public static final long ACTION_PREPARE_FROM_URI = 1 << 17;
|
||||
|
||||
/**
|
||||
* This is the default playback state and indicates that no media has been
|
||||
@@ -330,6 +343,10 @@ public final class PlaybackState implements Parcelable {
|
||||
* <li> {@link PlaybackState#STATE_REWINDING}</li>
|
||||
* <li> {@link PlaybackState#STATE_BUFFERING}</li>
|
||||
* <li> {@link PlaybackState#STATE_ERROR}</li>
|
||||
* <li> {@link PlaybackState#STATE_CONNECTING}</li>
|
||||
* <li> {@link PlaybackState#STATE_SKIPPING_TO_PREVIOUS}</li>
|
||||
* <li> {@link PlaybackState#STATE_SKIPPING_TO_NEXT}</li>
|
||||
* <li> {@link PlaybackState#STATE_SKIPPING_TO_QUEUE_ITEM}</li>
|
||||
* </ul>
|
||||
*/
|
||||
public int getState() {
|
||||
@@ -380,6 +397,10 @@ public final class PlaybackState implements Parcelable {
|
||||
* <li> {@link PlaybackState#ACTION_PLAY_FROM_SEARCH}</li>
|
||||
* <li> {@link PlaybackState#ACTION_SKIP_TO_QUEUE_ITEM}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PLAY_FROM_URI}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PREPARE}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PREPARE_FROM_MEDIA_ID}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PREPARE_FROM_SEARCH}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PREPARE_FROM_URI}</li>
|
||||
* </ul>
|
||||
*/
|
||||
public long getActions() {
|
||||
@@ -831,6 +852,10 @@ public final class PlaybackState implements Parcelable {
|
||||
* <li> {@link PlaybackState#STATE_REWINDING}</li>
|
||||
* <li> {@link PlaybackState#STATE_BUFFERING}</li>
|
||||
* <li> {@link PlaybackState#STATE_ERROR}</li>
|
||||
* <li> {@link PlaybackState#STATE_CONNECTING}</li>
|
||||
* <li> {@link PlaybackState#STATE_SKIPPING_TO_PREVIOUS}</li>
|
||||
* <li> {@link PlaybackState#STATE_SKIPPING_TO_NEXT}</li>
|
||||
* <li> {@link PlaybackState#STATE_SKIPPING_TO_QUEUE_ITEM}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param state The current state of playback.
|
||||
@@ -870,6 +895,10 @@ public final class PlaybackState implements Parcelable {
|
||||
* <li> {@link PlaybackState#STATE_REWINDING}</li>
|
||||
* <li> {@link PlaybackState#STATE_BUFFERING}</li>
|
||||
* <li> {@link PlaybackState#STATE_ERROR}</li>
|
||||
* <li> {@link PlaybackState#STATE_CONNECTING}</li>
|
||||
* <li> {@link PlaybackState#STATE_SKIPPING_TO_PREVIOUS}</li>
|
||||
* <li> {@link PlaybackState#STATE_SKIPPING_TO_NEXT}</li>
|
||||
* <li> {@link PlaybackState#STATE_SKIPPING_TO_QUEUE_ITEM}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param state The current state of playback.
|
||||
@@ -900,6 +929,10 @@ public final class PlaybackState implements Parcelable {
|
||||
* <li> {@link PlaybackState#ACTION_PLAY_FROM_SEARCH}</li>
|
||||
* <li> {@link PlaybackState#ACTION_SKIP_TO_QUEUE_ITEM}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PLAY_FROM_URI}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PREPARE}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PREPARE_FROM_MEDIA_ID}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PREPARE_FROM_SEARCH}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PREPARE_FROM_URI}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param actions The set of actions allowed.
|
||||
|
||||
@@ -868,6 +868,38 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
|
||||
}
|
||||
}
|
||||
|
||||
public void prepare() {
|
||||
try {
|
||||
mCb.onPrepare();
|
||||
} catch (RemoteException e) {
|
||||
Slog.e(TAG, "Remote failure in prepare.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void prepareFromMediaId(String mediaId, Bundle extras) {
|
||||
try {
|
||||
mCb.onPrepareFromMediaId(mediaId, extras);
|
||||
} catch (RemoteException e) {
|
||||
Slog.e(TAG, "Remote failure in prepareFromMediaId.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void prepareFromSearch(String query, Bundle extras) {
|
||||
try {
|
||||
mCb.onPrepareFromSearch(query, extras);
|
||||
} catch (RemoteException e) {
|
||||
Slog.e(TAG, "Remote failure in prepareFromSearch.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void prepareFromUri(Uri uri, Bundle extras) {
|
||||
try {
|
||||
mCb.onPrepareFromUri(uri, extras);
|
||||
} catch (RemoteException e) {
|
||||
Slog.e(TAG, "Remote failure in prepareFromUri.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void play() {
|
||||
try {
|
||||
mCb.onPlay();
|
||||
@@ -880,7 +912,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
|
||||
try {
|
||||
mCb.onPlayFromMediaId(mediaId, extras);
|
||||
} catch (RemoteException e) {
|
||||
Slog.e(TAG, "Remote failure in playUri.", e);
|
||||
Slog.e(TAG, "Remote failure in playFromMediaId.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1099,6 +1131,27 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare() throws RemoteException {
|
||||
mSessionCb.prepare();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareFromMediaId(String mediaId, Bundle extras)
|
||||
throws RemoteException {
|
||||
mSessionCb.prepareFromMediaId(mediaId, extras);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareFromSearch(String query, Bundle extras) throws RemoteException {
|
||||
mSessionCb.prepareFromSearch(query, extras);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareFromUri(Uri uri, Bundle extras) throws RemoteException {
|
||||
mSessionCb.prepareFromUri(uri, extras);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void play() throws RemoteException {
|
||||
mSessionCb.play();
|
||||
|
||||
Reference in New Issue
Block a user