From 501da109ced14c498eeafcd62d1fbe12e6ecc76e Mon Sep 17 00:00:00 2001 From: jbibik Date: Thu, 15 Jun 2023 14:31:59 +0100 Subject: [PATCH] Default RepeatMode for conversion is NONE/OFF Current behaviour causes an app to crash if it receives an unrecognized repeat mode send over the wire. In order to avoid the crash, a sensible default had to be chosen. For `Player.RepeatMode`, it is `Player.REPEAT_MODE_OFF`, which is the same value we use as default when unbundling `PlayerInfo`. For `PlaybackStateCompat.RepeatMode`, it is `PlaybackStateCompat.REPEAT_MODE_NONE`, which is what we use in the no-arg `LegacyPlayerInfo` constructor. Issue: androidx/media#448 #minor-release PiperOrigin-RevId: 540563792 --- .../androidx/media3/session/MediaUtils.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaUtils.java b/libraries/session/src/main/java/androidx/media3/session/MediaUtils.java index 9d90276bb2..cf078a7216 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaUtils.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaUtils.java @@ -971,8 +971,12 @@ import java.util.concurrent.TimeoutException; case PlaybackStateCompat.REPEAT_MODE_GROUP: return Player.REPEAT_MODE_ALL; default: - throw new IllegalArgumentException( - "Unrecognized PlaybackStateCompat.RepeatMode: " + playbackStateCompatRepeatMode); + Log.w( + TAG, + "Unrecognized PlaybackStateCompat.RepeatMode: " + + playbackStateCompatRepeatMode + + " was converted to `Player.REPEAT_MODE_OFF`"); + return Player.REPEAT_MODE_OFF; } } @@ -987,7 +991,12 @@ import java.util.concurrent.TimeoutException; case Player.REPEAT_MODE_ALL: return PlaybackStateCompat.REPEAT_MODE_ALL; default: - throw new IllegalArgumentException("Unrecognized RepeatMode: " + repeatMode); + Log.w( + TAG, + "Unrecognized RepeatMode: " + + repeatMode + + " was converted to `PlaybackStateCompat.REPEAT_MODE_NONE`"); + return PlaybackStateCompat.REPEAT_MODE_NONE; } } @@ -1392,9 +1401,9 @@ import java.util.concurrent.TimeoutException; * previousPlayerInfo} and taking into account the passed available commands. * * @param oldPlayerInfo The old {@link PlayerInfo}. - * @param oldBundlingExclusions The bundling exlusions in the old {@link PlayerInfo}. + * @param oldBundlingExclusions The bundling exclusions in the old {@link PlayerInfo}. * @param newPlayerInfo The new {@link PlayerInfo}. - * @param newBundlingExclusions The bundling exlusions in the new {@link PlayerInfo}. + * @param newBundlingExclusions The bundling exclusions in the new {@link PlayerInfo}. * @param availablePlayerCommands The available commands to take into account when merging. * @return A pair with the resulting {@link PlayerInfo} and {@link BundlingExclusions}. */