Android 类 AudioManager 中的音频焦点是什么?
AudioManager
类有一个方法 abandonAudioFocus()
和另一个方法 requestAudioFocus()
。我想知道什么是音频焦点?如果 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它与使用扬声器时的优先级有关,以防止同时播放许多内容或被覆盖。如果您
requestAudioFocus()
,您就声明您想要控制权。然后,您可以使用onAudioFocusChange(int focusChange)
进行监听,看看是否有其他东西尝试播放声音。您可能会被迫失去焦点(例如在打电话时),但稍后您可以重新获得焦点。完成后您应该abandonAudioFocus()
。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 withonAudioFocusChange(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 shouldabandonAudioFocus()
when you're finished.