Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is audio focus in Android class AudioManager?

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!

like image 265
Chris.Zou Avatar asked Jul 05 '11 03:07

Chris.Zou


People also ask

How do I get audio focus on android?

Audio focus in Android 8. 0 through Android 11. Beginning with Android 8.0 (API level 26), when you call requestAudioFocus() you must supply an AudioFocusRequest parameter. The AudioFocusRequest contains information about the audio context and capabilities of your app.

What is audio mode android?

Audio Manager in android is a class that provides access to the volume and modes of the device. Android audio manager helps us adjust the volume and ringing modes of devices based on our requirements. The modes that are well known to us, that are Ringing, Vibration, Loud, Silent, etc.

How do I use Audio Manager?

You can easily control your ringer volume and ringer profile i-e:(silent,vibrate,loud e.t.c) in android. Android provides AudioManager class that provides access to these controls. In order to use AndroidManager class, you have to first create an object of AudioManager class by calling the getSystemService() method.


1 Answers

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.

like image 141
karnok Avatar answered Nov 10 '22 21:11

karnok