Skip to content

Commit

Permalink
Default RepeatMode for conversion is NONE/OFF
Browse files Browse the repository at this point in the history
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#448

#minor-release

PiperOrigin-RevId: 540563792
  • Loading branch information
oceanjules authored and marcbaechinger committed Jun 19, 2023
1 parent 42915e9 commit 501da10
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,12 @@ public static int convertToBufferedPercentage(
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;
}
}

Expand All @@ -987,7 +991,12 @@ public static int convertToPlaybackStateCompatRepeatMode(@Player.RepeatMode int
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;
}
}

Expand Down Expand Up @@ -1392,9 +1401,9 @@ public static Commands intersect(@Nullable Commands commands1, @Nullable Command
* 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}.
*/
Expand Down

0 comments on commit 501da10

Please sign in to comment.