[BUG]: MediaPlayer can block the main thread (cause of ANR) #5650
Labels
bug
End user-perceivable behaviors which are not desirable.
Impact: Medium
Moderate perceived user impact (non-blocking bugs and general improvements).
Work: Medium
The means to find the solution is clear, but it isn't at good-first-issue level yet.
Milestone
Describe the bug
It seems that Android's
MediaPlayer
performs some blocking operations that, when interacted with on the main thread, can cause ANRs in certain conditions.Sample from the Play Console:
(Note that other thread stack traces have been removed for brevity since the main thread's stack trace seems sufficiently detailed to figure out what's going on here).
Steps To Reproduce
Unknown since this is an ANR reported by Android.
Expected Behavior
We should avoid avoidable ANRs.
Screenshots/Videos
No response
What device/emulator are you using?
Redmi Fire (Redmi 12)
Which Android version is your device/emulator running?
SDK 33
Which version of the Oppia Android app are you using?
0.14-beta-17f2ef3044
Additional Context
Note that this probably relates to #2430. It seems that per
MediaPlayer
's documentation that it doesn't require use on the main thread (though it's important to realize that its callbacks default to the main thread unless specifically configured to use a different handler/looper). I suspect that an ideal solution here may be to move all media player interactions to a background controller and have it liaise with the frontend using data providers (much in the same way that we do for other controllers in the app). We may need a mixin configuration (similar to that use for app language) to ensure that the controller is properly notified of lifecycle events for pausing/resuming/starting/stopping the media.Note that this solution also will allow other classes of issues to be fixed (including preserving play location across configuration changes).
Due to the sensitivity of media player, we should gate this fix behind a feature flag for thorough testing.
The text was updated successfully, but these errors were encountered: