Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 634
Emad-ud-deen Avatar asked Sep 06 '11 17:09

Emad-ud-deen


1 Answers

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
 }
like image 123
DonGru Avatar answered Sep 30 '22 17:09

DonGru