I'm encountering an issue with audio focus in my Android app using ExoPlayer. The scenario is as follows:
- A video is playing in my app.
- I switch to a browser (e.g., Chrome) and start playing a video (Let's say Live News From AajTak/NDTV News channel website)there, which pauses my app's video.
- When I switch back to my app and resume the video, it plays for a fraction of a second and then stops, citing PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS as the reason.
- Interestingly, the video in the browser has already paused.
This issue seems to occur even with other apps like YouTube (Play video in Youtube and then do above steps....YouTube video also stop after some time automatically), where they lose audio focus in a similar manner.
I'm looking for insights or solutions on how to handle this audio focus transition smoothly in my app. Is there a way to ensure stable audio focus regain in my app when resuming the video?
Any suggestions or advice on handling this audio focus issue effectively would be greatly appreciated.
Kindly mention your device's Android version as well as Exoplayer version you are using.
Checked this issue with Youtube app. Its reproduceable. To get over this issue, there may be following solutions:
This is difficult to fully control from developer side until the fix comes from Android framework level(I think).