What is audio focus in Android class AudioManager?

Chris.Zou picture Chris.Zou · Jul 5, 2011 · Viewed 16.4k times · Source

The AudioManager class has a method abandonAudioFocus() and another method requestAudioFocus(). I wonder what is audio focus? And what happens if an AudioManager object gets the audio focus or lost the audio focus?

Thank you!

Answer

karnok picture karnok · Jul 5, 2011

It has to do with priority when using the speakers, to prevent playing many things at once or being overridden. If you requestAudioFocus(), you're declaring that you want control. You can then listen with onAudioFocusChange(int focusChange) to see if anything else tries to play a sound. You may forcefully lose focus (like during a phone call) but then you can gain it later. You should abandonAudioFocus() when you're finished.