Naddy Naddy - 24 days ago 17
Android Question

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

How to control the default music player of android or any other player? By controlling i mean pause, play, next etc. Do i have to bind the service? I have tried to use the

IMediaPlaybackService
but it is not working. There is certainly a way out as i have seen apps in the android market which controls the music player. Any idea?

Answer
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";
Comments