安卓:检测另一个应用程序已经开始播放音频 [英] Android: Detect another application has started playing audio

查看:255
本文介绍了安卓:检测另一个应用程序已经开始播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的音乐应用程序不断播放的背景音乐,但我希望能够检测当其他应用程序开始播放音频(如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+.

推荐答案

<一个href="http://developer.android.com/reference/android/media/AudioManager.OnAudioFocusChangeListener.html">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.

<一个href="http://groups.google.com/group/android-developers/browse_thread/thread/db6822d84feaac6/219d8cba07795c61?hl=en&lnk=gst&q=OnAudioFocusChangeListener#219d8cba07795c61">http://groups.google.com/group/android-developers/browse_thread/thread/db6822d84feaac6/219d8cba07795c61?hl=en&lnk=gst&q=OnAudioFocusChangeListener#219d8cba07795c61

这篇关于安卓:检测另一个应用程序已经开始播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆