Reputation: 5183
I am working on an application that has media playing features.
I would like to honor AudioFocus
. I first request AudiFocus
:
audioManager.requestAudioFocus(new CustomOnAudioFocusChangeListener(), AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
This call returns either AUDIOFOCUS_REQUEST_FAILED
or AUDIOFOCUS_REQUEST_GRANTED
.
I guess I shouldn't start playback if I receive AUDIOFOCUS_REQUEST_FAILED
. But then what to do?
Will my CustomOnAudioFocusChangeListener
be notified when focus becomes available or is it only when you got AUTOFOCUS_REQUEST_GRANTED
that it starts getting updates?
Should I inform the user and ask him to try again later? Or retry programmatically after some time?
Thanks in advance
Upvotes: 3
Views: 2504
Reputation: 93589
What to do depends on how you want your app to react. You shouldn't start playing, you may want to message your user. Or if its something non-critical, you may silently ignore the failure and move on.
I believe you only get updates on the listener on success. You get the updates then so if you're lowered you can choose to duck your output or pause until you regain.
Upvotes: 2