android - 如何停止另一个应用程序的媒体播放器?

标签 android media-player

我正在为 Android 编写一个 mp3 播放器,我想在另一个应用程序(如 google play 音乐)开始播放时停止播放音乐,反之亦然。如何检查另一个播放器是否正在运行并停止另一个应用程序的播放器?

提前致谢!

最佳答案

如果您的目标是 Android 2.2 及更高版本,那么您可以查看 Audio Focus。请参阅文档 here .

来自文档:

When your application needs to output audio such as music or a notification, you should always request audio focus. Once it has focus, it can use the sound output freely, but it should always listen for focus changes. If it is notified that it has lost the audio focus, it should immediately either kill the audio or lower it to a quiet level (known as "ducking"—there is a flag that indicates which one is appropriate) and only resume loud playback after it receives focus again.

使用AudioManager请求音频焦点并实现AudioManager.OnAudioFocusChangeListener响应音频焦点变化。

关于android - 如何停止另一个应用程序的媒体播放器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21836122/

相关文章:

java - 尝试在回收者 View 中实现搜索

机器人:媒体播放器错误(1,-17)

java - 关闭应用程序时如何停止声音

android - 如何阻止 Media Player 播放多个声音

android - 焦点迷失在 adapter.notifyArrayItemRangeChanged 上

java - RecyclerView 不显示接收到的数据

javascript - 带有 XML 和按钮的动态 HTML5 播放器

windows-phone-8.1 - Windows Phone 8.1 音乐库获取当前媒体队列

java - 没有找到适合 startActivity(intent) 方法的方法

Android使用字符串资源绑定(bind)双值来查看