Control the default music player of android or any other music player

AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

if(mAudioManager.isMusicActive()) {
    Intent i = new Intent(SERVICECMD);
    i.putExtra(CMDNAME , CMDSTOP );
    YourApplicationClass.this.sendBroadcast(i);
}

you can by getting the audiomanager then sending commands to it.

these are the commands.

 public static final String CMDTOGGLEPAUSE = "togglepause";
 public static final String CMDPAUSE = "pause";
 public static final String CMDPREVIOUS = "previous";
 public static final String CMDNEXT = "next";
 public static final String SERVICECMD = "com.android.music.musicservicecommand";
 public static final String CMDNAME = "command";
 public static final String CMDSTOP = "stop";

Leave a Comment