Merge "Added MediaController.TransportControls#playFromUri."
This commit is contained in:
committed by
Android (Google) Code Review
commit
a130c1a74d
@@ -17062,6 +17062,7 @@ package android.media.session {
|
||||
method public void play();
|
||||
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 rewind();
|
||||
method public void seekTo(long);
|
||||
method public void sendCustomAction(android.media.session.PlaybackState.CustomAction, android.os.Bundle);
|
||||
@@ -17109,6 +17110,7 @@ package android.media.session {
|
||||
method public void onPlay();
|
||||
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 onRewind();
|
||||
method public void onSeekTo(long);
|
||||
method public void onSetRating(android.media.Rating);
|
||||
@@ -17163,6 +17165,7 @@ package android.media.session {
|
||||
field public static final long ACTION_PLAY = 4L; // 0x4L
|
||||
field public static final long ACTION_PLAY_FROM_MEDIA_ID = 1024L; // 0x400L
|
||||
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_REWIND = 8L; // 0x8L
|
||||
field public static final long ACTION_SEEK_TO = 256L; // 0x100L
|
||||
|
||||
@@ -18327,6 +18327,7 @@ package android.media.session {
|
||||
method public void play();
|
||||
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 rewind();
|
||||
method public void seekTo(long);
|
||||
method public void sendCustomAction(android.media.session.PlaybackState.CustomAction, android.os.Bundle);
|
||||
@@ -18374,6 +18375,7 @@ package android.media.session {
|
||||
method public void onPlay();
|
||||
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 onRewind();
|
||||
method public void onSeekTo(long);
|
||||
method public void onSetRating(android.media.Rating);
|
||||
@@ -18428,6 +18430,7 @@ package android.media.session {
|
||||
field public static final long ACTION_PLAY = 4L; // 0x4L
|
||||
field public static final long ACTION_PLAY_FROM_MEDIA_ID = 1024L; // 0x400L
|
||||
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_REWIND = 8L; // 0x8L
|
||||
field public static final long ACTION_SEEK_TO = 256L; // 0x100L
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
|
||||
package android.media.session;
|
||||
|
||||
import android.media.Rating;
|
||||
import android.content.Intent;
|
||||
import android.media.Rating;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.ResultReceiver;
|
||||
@@ -30,8 +30,9 @@ oneway interface ISessionCallback {
|
||||
|
||||
// These callbacks are for the TransportPerformer
|
||||
void onPlay();
|
||||
void onPlayFromMediaId(String uri, in Bundle extras);
|
||||
void onPlayFromMediaId(String mediaId, in Bundle extras);
|
||||
void onPlayFromSearch(String query, in Bundle extras);
|
||||
void onPlayFromUri(in Uri uri, in Bundle extras);
|
||||
void onSkipToTrack(long id);
|
||||
void onPause();
|
||||
void onStop();
|
||||
|
||||
@@ -23,9 +23,9 @@ import android.media.Rating;
|
||||
import android.media.routing.IMediaRouterDelegate;
|
||||
import android.media.routing.IMediaRouterStateCallback;
|
||||
import android.media.session.ISessionControllerCallback;
|
||||
import android.media.session.MediaSession;
|
||||
import android.media.session.ParcelableVolumeInfo;
|
||||
import android.media.session.PlaybackState;
|
||||
import android.media.session.MediaSession;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.ResultReceiver;
|
||||
@@ -55,8 +55,9 @@ interface ISessionController {
|
||||
|
||||
// These commands are for the TransportControls
|
||||
void play();
|
||||
void playFromMediaId(String uri, in Bundle extras);
|
||||
void playFromMediaId(String mediaId, in Bundle extras);
|
||||
void playFromSearch(String string, in Bundle extras);
|
||||
void playFromUri(in Uri uri, in Bundle extras);
|
||||
void skipToQueueItem(long id);
|
||||
void pause();
|
||||
void stop();
|
||||
|
||||
@@ -615,9 +615,9 @@ public final class MediaController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that the player start playback for a specific {@link Uri}.
|
||||
* Request that the player start playback for a specific media id.
|
||||
*
|
||||
* @param mediaId The uri of the requested media.
|
||||
* @param mediaId The id of the requested media.
|
||||
* @param extras Optional extras that can include extra information about the media item
|
||||
* to be played.
|
||||
*/
|
||||
@@ -655,6 +655,25 @@ public final class MediaController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that the player start playback for a specific {@link Uri}.
|
||||
*
|
||||
* @param uri The URI of the requested media.
|
||||
* @param extras Optional extras that can include extra information about the media item
|
||||
* to be played.
|
||||
*/
|
||||
public void playFromUri(Uri uri, Bundle extras) {
|
||||
if (uri == null || Uri.EMPTY.equals(uri)) {
|
||||
throw new IllegalArgumentException(
|
||||
"You must specify a non-empty Uri for playFromUri.");
|
||||
}
|
||||
try {
|
||||
mSessionBinder.playFromUri(uri, extras);
|
||||
} catch (RemoteException e) {
|
||||
Log.wtf(TAG, "Error calling play(" + uri + ").", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Play an item with a specific id in the play queue. If you specify an
|
||||
* id that is not in the play queue, the behavior is undefined.
|
||||
|
||||
@@ -30,6 +30,7 @@ import android.media.MediaMetadata;
|
||||
import android.media.Rating;
|
||||
import android.media.VolumeProvider;
|
||||
import android.media.routing.MediaRouter;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -541,6 +542,10 @@ public final class MediaSession {
|
||||
postToCallback(CallbackMessageHandler.MSG_PLAY_SEARCH, query, extras);
|
||||
}
|
||||
|
||||
private void dispatchPlayFromUri(Uri uri, Bundle extras) {
|
||||
postToCallback(CallbackMessageHandler.MSG_PLAY_URI, uri, extras);
|
||||
}
|
||||
|
||||
private void dispatchSkipToItem(long id) {
|
||||
postToCallback(CallbackMessageHandler.MSG_SKIP_TO_ITEM, id);
|
||||
}
|
||||
@@ -832,6 +837,12 @@ public final class MediaSession {
|
||||
public void onPlayFromSearch(String query, Bundle extras) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to handle requests to play a specific media item represented by a URI.
|
||||
*/
|
||||
public void onPlayFromUri(Uri uri, Bundle extras) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to handle requests to play an item with a given id from the
|
||||
* play queue.
|
||||
@@ -960,6 +971,14 @@ public final class MediaSession {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayFromUri(Uri uri, Bundle extras) {
|
||||
MediaSession session = mMediaSession.get();
|
||||
if (session != null) {
|
||||
session.dispatchPlayFromUri(uri, extras);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSkipToTrack(long id) {
|
||||
MediaSession session = mMediaSession.get();
|
||||
@@ -1171,6 +1190,7 @@ public final class MediaSession {
|
||||
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 MediaSession.Callback mCallback;
|
||||
|
||||
@@ -1210,6 +1230,9 @@ public final class MediaSession {
|
||||
case MSG_PLAY_SEARCH:
|
||||
mCallback.onPlayFromSearch((String) msg.obj, msg.getData());
|
||||
break;
|
||||
case MSG_PLAY_URI:
|
||||
mCallback.onPlayFromUri((Uri) msg.obj, msg.getData());
|
||||
break;
|
||||
case MSG_SKIP_TO_ITEM:
|
||||
mCallback.onSkipToQueueItem((Long) msg.obj);
|
||||
break;
|
||||
|
||||
@@ -125,6 +125,13 @@ public final class PlaybackState implements Parcelable {
|
||||
*/
|
||||
public static final long ACTION_SKIP_TO_QUEUE_ITEM = 1 << 12;
|
||||
|
||||
/**
|
||||
* Indicates this session supports the play from URI command.
|
||||
*
|
||||
* @see Builder#setActions(long)
|
||||
*/
|
||||
public static final long ACTION_PLAY_FROM_URI = 1 << 13;
|
||||
|
||||
/**
|
||||
* This is the default playback state and indicates that no media has been
|
||||
* added yet, or the performer has been reset and has no content to play.
|
||||
@@ -353,6 +360,11 @@ public final class PlaybackState implements Parcelable {
|
||||
* <li> {@link PlaybackState#ACTION_SKIP_TO_NEXT}</li>
|
||||
* <li> {@link PlaybackState#ACTION_SEEK_TO}</li>
|
||||
* <li> {@link PlaybackState#ACTION_SET_RATING}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PLAY_PAUSE}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PLAY_FROM_MEDIA_ID}</li>
|
||||
* <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>
|
||||
* </ul>
|
||||
*/
|
||||
public long getActions() {
|
||||
@@ -868,6 +880,11 @@ public final class PlaybackState implements Parcelable {
|
||||
* <li> {@link PlaybackState#ACTION_SKIP_TO_NEXT}</li>
|
||||
* <li> {@link PlaybackState#ACTION_SEEK_TO}</li>
|
||||
* <li> {@link PlaybackState#ACTION_SET_RATING}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PLAY_PAUSE}</li>
|
||||
* <li> {@link PlaybackState#ACTION_PLAY_FROM_MEDIA_ID}</li>
|
||||
* <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>
|
||||
* </ul>
|
||||
*
|
||||
* @param actions The set of actions allowed.
|
||||
|
||||
@@ -40,6 +40,7 @@ import android.media.session.MediaSession;
|
||||
import android.media.session.ParcelableVolumeInfo;
|
||||
import android.media.session.PlaybackState;
|
||||
import android.media.AudioAttributes;
|
||||
import android.net.Uri;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.DeadObjectException;
|
||||
@@ -887,6 +888,14 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
|
||||
}
|
||||
}
|
||||
|
||||
public void playFromUri(Uri uri, Bundle extras) {
|
||||
try {
|
||||
mCb.onPlayFromUri(uri, extras);
|
||||
} catch (RemoteException e) {
|
||||
Slog.e(TAG, "Remote failure in playFromUri.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void skipToTrack(long id) {
|
||||
try {
|
||||
mCb.onSkipToTrack(id);
|
||||
@@ -1102,6 +1111,11 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
|
||||
mSessionCb.playFromSearch(query, extras);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playFromUri(Uri uri, Bundle extras) throws RemoteException {
|
||||
mSessionCb.playFromUri(uri, extras);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skipToQueueItem(long id) {
|
||||
mSessionCb.skipToTrack(id);
|
||||
|
||||
Reference in New Issue
Block a user