summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2017-12-06 11:52:06 -0800
committerXin Li <delphij@google.com>2017-12-06 14:24:52 -0800
commiteaf9a16339fc4f4131a8b5615ee4abbd40f1d095 (patch)
treecf065e31f21d3f78bf6d4563c76821558bac3375
parent538c69661f30d126b6f95fe82713da429ac148b1 (diff)
parent387d6def447d72efe29a2fd97edeac32b51c136f (diff)
downloadLocalMediaPlayer-eaf9a16339fc4f4131a8b5615ee4abbd40f1d095.tar.gz
DO NOT MERGE: Merge Oreo MR1 into masterandroid-wear-8.0.0_r1
Exempt-From-Owner-Approval: Changes already landed internally Change-Id: I5f3aa9b079708476f94ea3df4eab98970961db7f
-rw-r--r--Android.mk4
-rw-r--r--src/com/android/car/media/localmediaplayer/Player.java36
2 files changed, 26 insertions, 14 deletions
diff --git a/Android.mk b/Android.mk
index a1d10ce..15f4580 100644
--- a/Android.mk
+++ b/Android.mk
@@ -14,6 +14,8 @@
# limitations under the License.
#
+ifneq ($(TARGET_BUILD_PDK), true)
+
LOCAL_PATH:= $(call my-dir)
# Proto dependencies
@@ -69,3 +71,5 @@ LOCAL_DEX_PREOPT := false
include packages/services/Car/car-support-lib/car-support.mk
include $(BUILD_PACKAGE)
+
+endif
diff --git a/src/com/android/car/media/localmediaplayer/Player.java b/src/com/android/car/media/localmediaplayer/Player.java
index 7f1850f..f70e05c 100644
--- a/src/com/android/car/media/localmediaplayer/Player.java
+++ b/src/com/android/car/media/localmediaplayer/Player.java
@@ -319,7 +319,7 @@ public class Player extends MediaSession.Callback {
return;
}
- mQueue = queue;
+ mQueue = new ArrayList<>(queue);
mCurrentQueueIdx = foundIdx;
QueueItem current = mQueue.get(mCurrentQueueIdx);
String path = current.getDescription().getExtras().getString(DataModel.PATH_KEY);
@@ -356,6 +356,7 @@ public class Player extends MediaSession.Callback {
.setStyle(new Notification.MediaStyle().setMediaSession(mSession.getSessionToken()))
.setContentTitle(current.getTitle())
.setContentText(current.getSubtitle())
+ .setShowWhen(false)
.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
mNotificationManager.notify(NOTIFICATION_ID, notification);
@@ -473,12 +474,20 @@ public class Player extends MediaSession.Callback {
mMediaPlayer.reset();
mMediaPlayer.setDataSource(path);
mMediaPlayer.prepare();
- mMediaPlayer.start();
if (metadata != null) {
mSession.setMetadata(metadata);
}
- updatePlaybackStatePlaying();
+ boolean wasGrantedAudio = requestAudioFocus(() -> {
+ mMediaPlayer.start();
+ updatePlaybackStatePlaying();
+ });
+ if (!wasGrantedAudio) {
+ // player.pause() isn't needed since it should not actually be playing, the
+ // other steps like, updating the notification and play state are needed, thus we
+ // call the pause method.
+ pausePlayback();
+ }
}
private void safeAdvance() {
@@ -508,13 +517,19 @@ public class Player extends MediaSession.Callback {
Log.d(TAG, "Shuffling");
}
- if (mQueue != null) {
+ // rebuild the the queue in a shuffled form.
+ if (mQueue != null && mQueue.size() > 2) {
QueueItem current = mQueue.remove(mCurrentQueueIdx);
Collections.shuffle(mQueue);
mQueue.add(0, current);
+ // A QueueItem contains a queue id that's used as the key for when the user selects
+ // the current play list. This means the QueueItems must be rebuilt to have their new
+ // id's set.
+ for (int i = 0; i < mQueue.size(); i++) {
+ mQueue.set(i, new QueueItem(mQueue.get(i).getDescription(), i));
+ }
mCurrentQueueIdx = 0;
updateSessionQueueState();
- updatePlaybackStatePlaying();
}
}
@@ -546,16 +561,9 @@ public class Player extends MediaSession.Callback {
@Override
public void onSkipToQueueItem(long id) {
- int idx = (int) id;
- MediaSession.QueueItem item = mQueue.get(idx);
- MediaDescription description = item.getDescription();
-
- String path = description.getExtras().getString(DataModel.PATH_KEY);
- MediaMetadata metadata = mDataModel.getMetadata(description.getMediaId());
-
try {
- play(path, metadata);
- mCurrentQueueIdx = idx;
+ mCurrentQueueIdx = (int) id;
+ playCurrentQueueIndex();
} catch (IOException e) {
Log.e(TAG, "Failed to play.", e);
mSession.setPlaybackState(mErrorState);