MediaSession: Add new methods for preparing media content
Introduced new methods for preparing media content: prepare,
prepareFromMediaId, prepareFromSearch, and prepareFromUri. These methods
allow MediaSession prepare media content rather than play
it. MediaSession will set up a queue or buffer their content during
these preparing requests.
The constants, FLAG_HANDLES_PREPARE_ONLY and EXTRA_PREPARE_ONLY, are
removed because the introduced methods can replace them.
Bug:25841735, Bug:25153060, Bug:25153353
Change-Id: I8fa2097c98fe2fba92b267d2865a9b75d118af09
diff --git a/api/current.txt b/api/current.txt
index 617aac0..a9e5878 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -22542,6 +22542,10 @@
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);
@@ -22575,7 +22579,6 @@
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
}
@@ -22590,6 +22593,10 @@
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);
@@ -22646,6 +22653,10 @@
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
@@ -22654,7 +22665,6 @@
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
diff --git a/api/system-current.txt b/api/system-current.txt
index ec422c0..a93e328 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -24114,6 +24114,10 @@
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);
@@ -24147,7 +24151,6 @@
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
}
@@ -24162,6 +24165,10 @@
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);
@@ -24218,6 +24225,10 @@
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
@@ -24226,7 +24237,6 @@
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
diff --git a/api/test-current.txt b/api/test-current.txt
index d202108..6bf3beec 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -22551,6 +22551,10 @@
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);
@@ -22584,7 +22588,6 @@
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
}
@@ -22599,6 +22602,10 @@
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);
@@ -22655,6 +22662,10 @@
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
@@ -22663,7 +22674,6 @@
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
diff --git a/media/java/android/media/session/ISessionCallback.aidl b/media/java/android/media/session/ISessionCallback.aidl
index adb6b06..893bd3c 100644
--- a/media/java/android/media/session/ISessionCallback.aidl
+++ b/media/java/android/media/session/ISessionCallback.aidl
@@ -29,6 +29,10 @@
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);
diff --git a/media/java/android/media/session/ISessionController.aidl b/media/java/android/media/session/ISessionController.aidl
index 285e5f7..249bcdc 100644
--- a/media/java/android/media/session/ISessionController.aidl
+++ b/media/java/android/media/session/ISessionController.aidl
@@ -50,6 +50,10 @@
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);
diff --git a/media/java/android/media/session/MediaController.java b/media/java/android/media/session/MediaController.java
index 3d9b60d..13db00e 100644
--- a/media/java/android/media/session/MediaController.java
+++ b/media/java/android/media/session/MediaController.java
@@ -592,6 +592,90 @@
}
/**
+ * 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.
*/
public void play() {
@@ -605,7 +689,6 @@
/**
* 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 @@
* 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 @@
/**
* 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.
*/
diff --git a/media/java/android/media/session/MediaSession.java b/media/java/android/media/session/MediaSession.java
index 8c5b19c..3b1b6c8 100644
--- a/media/java/android/media/session/MediaSession.java
+++ b/media/java/android/media/session/MediaSession.java
@@ -87,12 +87,6 @@
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
* regardless of the current ordering in the system.
@@ -106,7 +100,6 @@
@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 @@
}
}
+ 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 @@
}
/**
- * 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() {
}
/**
@@ -827,6 +869,13 @@
}
/**
+ * 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.
*/
public void onPlayFromUri(Uri uri, Bundle extras) {
@@ -937,6 +986,38 @@
}
@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();
if (session != null) {
@@ -1162,24 +1243,28 @@
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 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 @@
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;
diff --git a/media/java/android/media/session/PlaybackState.java b/media/java/android/media/session/PlaybackState.java
index 1079a1f..1485cd7 100644
--- a/media/java/android/media/session/PlaybackState.java
+++ b/media/java/android/media/session/PlaybackState.java
@@ -133,19 +133,32 @@
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 @@
* <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 @@
* <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 @@
* <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 @@
* <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 @@
* <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.
diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java
index 246da2e..862c061 100644
--- a/services/core/java/com/android/server/media/MediaSessionRecord.java
+++ b/services/core/java/com/android/server/media/MediaSessionRecord.java
@@ -868,6 +868,38 @@
}
}
+ 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 @@
try {
mCb.onPlayFromMediaId(mediaId, extras);
} catch (RemoteException e) {
- Slog.e(TAG, "Remote failure in playUri.", e);
+ Slog.e(TAG, "Remote failure in playFromMediaId.", e);
}
}
@@ -1100,6 +1132,27 @@
}
@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();
}