开发者

How do you check if music is playing by using a broadcast receiver?

开发者 https://www.devze.com 2023-04-02 16:34 出处:网络
I would like to prevent some of my code from executing only when music or videos are currently playing. How would I accomplish this usi开发者_开发百科ng a broadcast receiver?You don\'t need a broadcas

I would like to prevent some of my code from executing only when music or videos are currently playing. How would I accomplish this usi开发者_开发百科ng a broadcast receiver?


You don't need a broadcast receiver for this - AudioManager is your friend:

AudioManager.isMusicActive() does the job you want, have a closer look here for details: AudioManager

here is an example:

AudioManager manager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
if(manager.isMusicActive())
 {
     // do something - or do it not
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号