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

人走茶凉 提交于 2019-11-26 12:43:05

问题


I would like to prevent some of my code from executing only when music or videos are currently playing. How would I accomplish this using a broadcast receiver?


回答1:


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
 }


来源:https://stackoverflow.com/questions/7323915/how-do-you-check-if-music-is-playing-by-using-a-broadcast-receiver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!