From 6c7fbe8b52bfa45710f9d7753efa14ef965d5494 Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Tue, 29 Oct 2019 11:39:18 +0000 Subject: [PATCH] Add shuffle and repeat modes to media session playback state invalidation Which ensures both get updated when the MediaSessionConnector player changes. Issue:#6582 PiperOrigin-RevId: 277254889 --- RELEASENOTES.md | 4 +++- .../mediasession/MediaSessionConnector.java | 22 ++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 685026cdb33..a11131635b2 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -2,9 +2,11 @@ ### 2.10.7 ### +* HLS: Fix detection of Dolby Atmos to match the HLS authoring specification. +* MediaSession extension: Update shuffle and repeat modes when playback state + is invalidated ([#6582](https://github.com/google/ExoPlayer/issues/6582)). * Fix the start of audio getting truncated when transitioning to a new item in a playlist of opus streams. -* Fix detection of Dolby Atmos in HLS to match the HLS authoring specification. ### 2.10.6 (2019-10-17) ### diff --git a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java index 81e9a14f482..284acd8d112 100644 --- a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java +++ b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java @@ -751,6 +751,18 @@ public final void invalidateMediaSessionPlaybackState() { sessionPlaybackSpeed, /* updateTime= */ SystemClock.elapsedRealtime()) .setExtras(extras); + + @Player.RepeatMode int repeatMode = player.getRepeatMode(); + mediaSession.setRepeatMode( + repeatMode == Player.REPEAT_MODE_ONE + ? PlaybackStateCompat.REPEAT_MODE_ONE + : repeatMode == Player.REPEAT_MODE_ALL + ? PlaybackStateCompat.REPEAT_MODE_ALL + : PlaybackStateCompat.REPEAT_MODE_NONE); + mediaSession.setShuffleMode( + player.getShuffleModeEnabled() + ? PlaybackStateCompat.SHUFFLE_MODE_ALL + : PlaybackStateCompat.SHUFFLE_MODE_NONE); mediaSession.setPlaybackState(builder.build()); } @@ -1050,21 +1062,11 @@ public void onIsPlayingChanged(boolean isPlaying) { @Override public void onRepeatModeChanged(@Player.RepeatMode int repeatMode) { - mediaSession.setRepeatMode( - repeatMode == Player.REPEAT_MODE_ONE - ? PlaybackStateCompat.REPEAT_MODE_ONE - : repeatMode == Player.REPEAT_MODE_ALL - ? PlaybackStateCompat.REPEAT_MODE_ALL - : PlaybackStateCompat.REPEAT_MODE_NONE); invalidateMediaSessionPlaybackState(); } @Override public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) { - mediaSession.setShuffleMode( - shuffleModeEnabled - ? PlaybackStateCompat.SHUFFLE_MODE_ALL - : PlaybackStateCompat.SHUFFLE_MODE_NONE); invalidateMediaSessionPlaybackState(); invalidateMediaSessionQueue(); }