What is audio focus in Android class AudioManager?

拥有回忆 提交于 2019-12-09 02:51:19

问题


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!


回答1:


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.




回答2:


You use audio focus when setting which app has the playback priority. For example, you can set up what should your app do when it's playing a audio file and some other app wants to take the focus and play something. If you do not set up what will happen it these cases, the other app will just play audio over yours. I've written a blog post about this: http://markojerkic.com/handling-audio-focus-in-android/



来源:https://stackoverflow.com/questions/6577646/what-is-audio-focus-in-android-class-audiomanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!