我正在为 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/