You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to have a way to receive focus loss events from the default AudioFocusManager. As far as I know, if another app starts playing and requests focus, we will receive an onPlayWhenReadyChanged event with the correct reason (PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS). However, if we pause our app and then the other app starts playing, the focus loss is not notified.
Use case description
I want to have access to the focus state value to improve my "Resume on headset insertion" feature.
Currently, I have an AudioManager.ACTION_HEADSET_PLUG receiver to resume the playback if it was previously paused with a PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY reason. Unfortunately, if a user listening to my app does the following:
Disconnects the headset
Starts playing something in another app
Reconnects the headset to listen to that other app
My feature will resume the playback when it shouldn't. I would like to use the focus state value to skip the resume action in those cases.
Possible solutions
I wonder how feasible it would be to add a way to query the current focus state and/or listen to some EVENT_AUDIO_FOCUS_LOSSPlayerEvent that is emitted even when playWhenReady is already false.
I know I can use setAudioAttributes to handle audio focus myself, but I would need to recreate the entire AudioFocusManager class and even override important methods from Player just to start handling the focus. After seeing how tightly coupled the default AudioFocusManager is with ExoPlayerImpl, I'm concerned about missing some edge cases and leaving my app in a bad state just to receive a focus loss event.
Apologies if this is something we can already do. If not, I also understand that it is not that important to have, but since this is information that AudioFocusManager already has, I wonder if there is a way to expose this to clients. Thank you.
The text was updated successfully, but these errors were encountered:
Thanks for reporting! I think the original intention was to re-report Player.Listener.onPlayWhenReadyChanged with a new reason if the reason for being paused changed to PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS. We'll see that we can fix that and then you should be able to see this callback while your app is paused.
Some cases are not handled correctly at the moment:
- Pausing during suppressed playback should not clear the
suppression state.
- Transient focus loss while paused should be reported as
a playback suppression.
Issue: #1436
#cherrypick
PiperOrigin-RevId: 644971218
Some cases are not handled correctly at the moment:
- Pausing during suppressed playback should not clear the
suppression state.
- Transient focus loss while paused should be reported as
a playback suppression.
Issue: #1436
#cherrypick
PiperOrigin-RevId: 644971218
(cherry picked from commit e84bb0d)
I would like to have a way to receive focus loss events from the default
AudioFocusManager
. As far as I know, if another app starts playing and requests focus, we will receive anonPlayWhenReadyChanged
event with the correct reason (PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS
). However, if we pause our app and then the other app starts playing, the focus loss is not notified.Use case description
I want to have access to the focus state value to improve my "Resume on headset insertion" feature.
Currently, I have an
AudioManager.ACTION_HEADSET_PLUG
receiver to resume the playback if it was previously paused with aPLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY
reason. Unfortunately, if a user listening to my app does the following:My feature will resume the playback when it shouldn't. I would like to use the focus state value to skip the resume action in those cases.
Possible solutions
I wonder how feasible it would be to add a way to query the current focus state and/or listen to some
EVENT_AUDIO_FOCUS_LOSS
Player
Event
that is emitted even whenplayWhenReady
is already false.I know I can use
setAudioAttributes
to handle audio focus myself, but I would need to recreate the entireAudioFocusManager
class and even override important methods fromPlayer
just to start handling the focus. After seeing how tightly coupled the defaultAudioFocusManager
is withExoPlayerImpl
, I'm concerned about missing some edge cases and leaving my app in a bad state just to receive a focus loss event.Apologies if this is something we can already do. If not, I also understand that it is not that important to have, but since this is information that
AudioFocusManager
already has, I wonder if there is a way to expose this to clients. Thank you.The text was updated successfully, but these errors were encountered: