diff --git a/api/current.txt b/api/current.txt index 658478be435c2..abc9e9a2b1636 100644 --- a/api/current.txt +++ b/api/current.txt @@ -22553,6 +22553,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); @@ -22586,7 +22590,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 } @@ -22601,6 +22604,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); @@ -22657,6 +22664,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 @@ -22665,7 +22676,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 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 6646c28b43be4..b36d7e89cb8d1 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -24126,6 +24126,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); @@ -24159,7 +24163,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 } @@ -24174,6 +24177,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); @@ -24230,6 +24237,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 @@ -24238,7 +24249,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 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 f1908c150b428..3878fbf25e315 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -22562,6 +22562,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); @@ -22595,7 +22599,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 } @@ -22610,6 +22613,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); @@ -22666,6 +22673,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 @@ -22674,7 +22685,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 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 adb6b0600f972..893bd3c8cbb13 100644 --- a/media/java/android/media/session/ISessionCallback.aidl +++ b/media/java/android/media/session/ISessionCallback.aidl @@ -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); diff --git a/media/java/android/media/session/ISessionController.aidl b/media/java/android/media/session/ISessionController.aidl index 285e5f7a0880a..249bcdc802cea 100644 --- a/media/java/android/media/session/ISessionController.aidl +++ b/media/java/android/media/session/ISessionController.aidl @@ -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); diff --git a/media/java/android/media/session/MediaController.java b/media/java/android/media/session/MediaController.java index 3d9b60deed2f6..13db00ef3cd1c 100644 --- a/media/java/android/media/session/MediaController.java +++ b/media/java/android/media/session/MediaController.java @@ -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. */ diff --git a/media/java/android/media/session/MediaSession.java b/media/java/android/media/session/MediaSession.java index 8c5b19c36f116..3b1b6c86ffcb0 100644 --- a/media/java/android/media/session/MediaSession.java +++ b/media/java/android/media/session/MediaSession.java @@ -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; diff --git a/media/java/android/media/session/PlaybackState.java b/media/java/android/media/session/PlaybackState.java index 1079a1f9a1077..1485cd782605a 100644 --- a/media/java/android/media/session/PlaybackState.java +++ b/media/java/android/media/session/PlaybackState.java @@ -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 { *
  • {@link PlaybackState#STATE_REWINDING}
  • *
  • {@link PlaybackState#STATE_BUFFERING}
  • *
  • {@link PlaybackState#STATE_ERROR}
  • + *
  • {@link PlaybackState#STATE_CONNECTING}
  • + *
  • {@link PlaybackState#STATE_SKIPPING_TO_PREVIOUS}
  • + *
  • {@link PlaybackState#STATE_SKIPPING_TO_NEXT}
  • + *
  • {@link PlaybackState#STATE_SKIPPING_TO_QUEUE_ITEM}
  • * */ public int getState() { @@ -380,6 +397,10 @@ public final class PlaybackState implements Parcelable { *
  • {@link PlaybackState#ACTION_PLAY_FROM_SEARCH}
  • *
  • {@link PlaybackState#ACTION_SKIP_TO_QUEUE_ITEM}
  • *
  • {@link PlaybackState#ACTION_PLAY_FROM_URI}
  • + *
  • {@link PlaybackState#ACTION_PREPARE}
  • + *
  • {@link PlaybackState#ACTION_PREPARE_FROM_MEDIA_ID}
  • + *
  • {@link PlaybackState#ACTION_PREPARE_FROM_SEARCH}
  • + *
  • {@link PlaybackState#ACTION_PREPARE_FROM_URI}
  • * */ public long getActions() { @@ -831,6 +852,10 @@ public final class PlaybackState implements Parcelable { *
  • {@link PlaybackState#STATE_REWINDING}
  • *
  • {@link PlaybackState#STATE_BUFFERING}
  • *
  • {@link PlaybackState#STATE_ERROR}
  • + *
  • {@link PlaybackState#STATE_CONNECTING}
  • + *
  • {@link PlaybackState#STATE_SKIPPING_TO_PREVIOUS}
  • + *
  • {@link PlaybackState#STATE_SKIPPING_TO_NEXT}
  • + *
  • {@link PlaybackState#STATE_SKIPPING_TO_QUEUE_ITEM}
  • * * * @param state The current state of playback. @@ -870,6 +895,10 @@ public final class PlaybackState implements Parcelable { *
  • {@link PlaybackState#STATE_REWINDING}
  • *
  • {@link PlaybackState#STATE_BUFFERING}
  • *
  • {@link PlaybackState#STATE_ERROR}
  • + *
  • {@link PlaybackState#STATE_CONNECTING}
  • + *
  • {@link PlaybackState#STATE_SKIPPING_TO_PREVIOUS}
  • + *
  • {@link PlaybackState#STATE_SKIPPING_TO_NEXT}
  • + *
  • {@link PlaybackState#STATE_SKIPPING_TO_QUEUE_ITEM}
  • * * * @param state The current state of playback. @@ -900,6 +929,10 @@ public final class PlaybackState implements Parcelable { *
  • {@link PlaybackState#ACTION_PLAY_FROM_SEARCH}
  • *
  • {@link PlaybackState#ACTION_SKIP_TO_QUEUE_ITEM}
  • *
  • {@link PlaybackState#ACTION_PLAY_FROM_URI}
  • + *
  • {@link PlaybackState#ACTION_PREPARE}
  • + *
  • {@link PlaybackState#ACTION_PREPARE_FROM_MEDIA_ID}
  • + *
  • {@link PlaybackState#ACTION_PREPARE_FROM_SEARCH}
  • + *
  • {@link PlaybackState#ACTION_PREPARE_FROM_URI}
  • * * * @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 246da2e10de52..862c061c6b9c5 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 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();