Ignore playback state update if state is the same
am: 9c698fe51d
Change-Id: Ibedf55ef3366e101c55775c5bd86b71cd4e95846
diff --git a/service/src/com/android/car/CarMediaService.java b/service/src/com/android/car/CarMediaService.java
index 5728bf2..bda7fbc 100644
--- a/service/src/com/android/car/CarMediaService.java
+++ b/service/src/com/android/car/CarMediaService.java
@@ -51,7 +51,6 @@
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
@@ -273,9 +272,12 @@
private class MediaControllerCallback extends MediaController.Callback {
private final MediaController mMediaController;
+ private int mPreviousPlaybackState;
private MediaControllerCallback(MediaController mediaController) {
mMediaController = mediaController;
+ PlaybackState state = mediaController.getPlaybackState();
+ mPreviousPlaybackState = (state == null) ? PlaybackState.STATE_NONE : state.getState();
}
private void register() {
@@ -288,10 +290,11 @@
@Override
public void onPlaybackStateChanged(@Nullable PlaybackState state) {
- if (state.getState() == PlaybackState.STATE_PLAYING) {
- updatePrimaryMediaSourceWithCurrentlyPlaying(
- Collections.singletonList(mMediaController));
+ if (state.getState() == PlaybackState.STATE_PLAYING
+ && state.getState() != mPreviousPlaybackState) {
+ setPrimaryMediaSource(mMediaController.getPackageName());
}
+ mPreviousPlaybackState = state.getState();
}
}