0

Is there a way we can check programmatically Which Music player is playing right now?

like Google Play, Samsung default Music Player, any 3rd party music player

Actually, we need to programmatically handle play/pause of music player. Google Play and Samsung Music works differently with code :

// Google Play do not play pause with this code
// it is using different package name i guess
CmdStop = "togglepause";
i = new Intent("com.android.music.musicservicecommand.togglepause");
i.putExtra(CmdName, CmdStop);
context.sendBroadcast(i);

Any help is appriciated

Thank you

almightyGOSU
  • 3,731
  • 6
  • 31
  • 41
Kushal
  • 8,100
  • 9
  • 63
  • 82

1 Answers1

4

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

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

stackoverflow answer

Community
  • 1
  • 1
Kanaiya Katarmal
  • 5,974
  • 4
  • 30
  • 56
  • This will give whether music is running or not.. I need to check which player is playing songs now? – Kushal Jun 09 '15 at 07:10
  • 2
    @Kushal the code above and http://developer.android.com/reference/android/media/AudioManager.html#dispatchMediaKeyEvent(android.view.KeyEvent) should allow you to handle play/pause without needing to know which player is running. – Bhullnatik Jun 09 '15 at 07:28
  • 1
    @Kanaiya please add answer how to check audio status like play, pause or stop. – Ajit Kumar Dubey Apr 27 '16 at 09:49