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

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

问题描述

我的音乐应用程序不断在后台播放音乐,但是我希望能够检测到另一个应用程序何时开始播放音频(例如 YouTube 应用程序),以便我可以在我的应用程序中暂停/静音/停止音频.

这将允许用户在听音乐的同时继续浏览网页,但是如果他们想随时观看视频,他们可以在没有音频冲突的情况下进行.

一种解决方案可能是监听应用程序何时开始使用 AudioManager 的广播.是否存在这样的 Intent Action?

<小时>

就像下面提供的答案一样,似乎有一种方法可以使用 AudioManager.OnAudioFocusChangeListener 检测 2.2 中音频焦点的丢失.

很好,但是对于更常见的 Android 版本有没有解决方案?最好 1.5+.

解决方案

http://developer.android.com/reference/android/media/AudioManager.OnAudioFocusChangeListener.html

此主题还有其他信息,可能会让您朝着正确的方向前进.

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

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.

One solution might be to listen for a broadcast which states when an application begins using the AudioManager. Does such an Intent Action exist?


Edit: 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.

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

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

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