Android:如何监听 MediaPlayer 事件,例如音乐播放/停止?
是否存在广播接收器操作来监听媒体播放器事件,例如检测音乐开始播放/停止或检测媒体播放器的播放/停止按钮的点击?
更一般地说,我想检测音频流何时开始/结束。
谢谢
Does it exists a broadcast receiver action in order to listen a Media Player event such as the detection of the music starting to play/stop or the detection of the hit of Play/Stop Button of the MediaPlayer ?
More generally I'd like to detect when the audio stream is starting/ending.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试
requestAudioFocus()
在您想要收听的流上注册音频焦点侦听器。您实际上不需要播放此流。当您收到
AUDIOFOCUS_LOSS
时,这意味着另一个“音频流正在启动”。当您收到
AUDIOFOCUS_GAIN
时,这意味着另一个“音频流正在结束”。如果您对音乐流感兴趣,
isMusicActive()
也可能对您有所帮助。You can try
requestAudioFocus()
to register an audio focus listener on a stream which you want to listen on. You don't need to play this stream actually.When you get
AUDIOFOCUS_LOSS
, it means another "audio stream is starting".When you get
AUDIOFOCUS_GAIN
, it means another "audio stream is ending".If you are interested in music stream,
isMusicActive()
may also help you.