문제

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?

도움이 되었습니까?

해결책

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
 }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top