release-request-ee600ee1-fadc-4a92-9feb-e22548c84a75-for-git_oc-mr1-release-4318546 snap-temp-L23800000099760172
Change-Id: Ie1acfcd66c1fb104d5519e1f8021b62e001119d7
diff --git a/src/com/android/car/media/localmediaplayer/Player.java b/src/com/android/car/media/localmediaplayer/Player.java
index 9aa86be..f70e05c 100644
--- a/src/com/android/car/media/localmediaplayer/Player.java
+++ b/src/com/android/car/media/localmediaplayer/Player.java
@@ -474,12 +474,20 @@
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() {
@@ -522,7 +530,6 @@
}
mCurrentQueueIdx = 0;
updateSessionQueueState();
- updatePlaybackStatePlaying();
}
}