我的音乐应用程序不断播放的背景音乐,但我希望能够检测当其他应用程序开始播放音频(如YouTube应用程序),这样我就可以暂停/静音/停止在我的应用程序中的音频。
My music application constantly plays music in the background, however I'd like to be able to detect when another application starts playing audio (such as the YouTube app) so I can pause/mute/stop the audio in my application.
这将允许用户继续浏览网页的同时听音乐,但如果他们想在任何时候观看视频,他们可以这样做,不带音频的冲突。
This will allow a user to continue browsing the web whilst listening to music, but then if they wish to watch a video at any point, they can do so without audio conflict.
一个解决办法可能是监听广播,当应用程序开始时使用AudioManager该条规定。有没有这样的意图行动存在?
One solution might be to listen for a broadcast which states when an application begins using the AudioManager. Does such an Intent Action exist?
编辑:作为在下面提供的答案,似乎有一种检测音频焦点在2.2损失 AudioManager.OnAudioFocusChangeListener 。
As in the answer provided below, there appears to be a method of detecting the loss of audio focus in 2.2 with AudioManager.OnAudioFocusChangeListener
.
大,但有对于Android的更常见版本的解决方案?理想的情况是1.5 +。
Great, but is there a solution for the more common versions of Android? Ideally 1.5+.
推荐答案
http://developer.android.com/reference/android/media/AudioManager.OnAudioFocusChangeListener.html
这线程也有可能让你在正确的方向前进航向的更多信息。
this thread also has additional information that might get you heading in the right direction.
http://groups.google.com/group/android-developers/browse_thread/thread/db6822d84feaac6/219d8cba07795c61?hl=en&lnk=gst&q=OnAudioFocusChangeListener#219d8cba07795c61
相关推荐
最新文章