Skip to content

Adding fallback handling for MediaUtils.convertToRepeatMode() in MediaControllerImplLegacy #448

@h6ah4i

Description

@h6ah4i

What's the matter?

I am using a forked version of the media3 library for my app to work around a specific issue. The problem is that some apps maybe use their own extended definition of repeat mode.

At least, the app I can find that causes the problem is Stellio. This app has two special repeat modes that cannot be handled by MediaUtils.convertToRepeatMode()

  • Jump to a next list - Stop on last track
    • 👉 representation code in decimal: 100
  • Jump to a next list - Stop from first list
    • 👉 representation code in decimal: 101

Proposed solution

Wrap the MediaUtils.convertToRepeatMode() call with a try-catch block and fallback to an alternative repeat mode like this.

repeatMode = MediaUtils.convertToRepeatMode(newLegacyPlayerInfo.repeatMode);

-    repeatMode = MediaUtils.convertToRepeatMode(newLegacyPlayerInfo.repeatMode);
+    try {
+      repeatMode = MediaUtils.convertToRepeatMode(newLegacyPlayerInfo.repeatMode);
+    } catch (IllegalArgumentException e) {
+      repeatMode = Player.REPEAT_MODE_OFF;
+    }

I think calling MediaUtils.convertToShuffleModeEnabled() is somewhat dangerous too due to the same reason, but I don't find the app that causes the error in the real world for now.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions