1

I am creating an application in which in have to detect music player states like playing, pause, stop.

i searched and found

AudioManager manager = (AudioManager) FlashLightActivity.this.getSystemService(Context.AUDIO_SERVICE); if(manager.isMusicActive()) { Toast.makeText(FlashLightActivity.this, "Music is playing..", Toast.LENGTH_LONG).show(); }else{ Toast.makeText(FlashLightActivity.this, "Music has stopped..", Toast.LENGTH_LONG).show(); }

By using above code i am not able to detect music state if my application is in running mode.

Above code will check this condition at starting of the application. i wanna use broadcast receiver for detecting the state of background music.

  • Possible duplicate of http://stackoverflow.com/questions/7323915/how-do-you-check-if-music-is-playing-by-using-a-broadcast-receiver – Kushal Apr 02 '15 at 11:06

1 Answers1

0

Above code will check this condition at starting of the application

I will be stunned if it does so reliably. There is no requirement that any app tell AudioManager that it is playing music.

i wanna use broadcast receiver for detecting the state of background music.

There are thousands upon thousands of music players available for Android. There are no requirements that any of them implement broadcasts to tell you of the state of music playback. There are not even some standard broadcasts in the SDK that you could reasonably hope that some of those players might use.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for you reply. i am not using any music player in my application but i wanna check, music player is playing or pause or stop. not in the starting of my application. – Vijay Arora Aug 24 '13 at 12:07
  • Suppose music is playing in the background i opened my application it detected that music is playing. now if i paused/stopped music then how will i recognize that music has stopped. – Vijay Arora Aug 24 '13 at 12:11
  • 1
    @VijayArora: I covered this in my answer. There are no such broadcasts required of music players, and there are thousands of such music players. You are welcome to contact each music player developer and ask them to implement such broadcasts. – CommonsWare Aug 24 '13 at 12:15
  • how can i contact them do you have any link for this.? – Vijay Arora Aug 24 '13 at 12:20
  • 1
    @VijayArora: There is contact information on each app's page in the Play Store. – CommonsWare Aug 24 '13 at 12:21