Android application to Pause/Resume the music of another music player app

Aniruddha Mukherjee picture Aniruddha Mukherjee · Feb 26, 2011 · Viewed 10.2k times · Source

In my Android application, I am playing different mp3 files using the MediaPlayer class.

The user is playing his/her own music with the default music application.

I want to:

  1. Pause the music of the default music application.
  2. Start playing music from my application.
  3. When my music is done playing, my app will resume the user's default music.

I want to pause and resume the music of the default music player from my application.

Is it possible to do this?

Answer

Mcingwe picture Mcingwe · Oct 17, 2011

The following code will pause a default MediaPlayer by sending a broadcast:

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

if (mAudioManager.isMusicActive()) {

    Intent i = new Intent("com.android.music.musicservicecommand");

    i.putExtra("command", "pause");
    YourApplicationClass.this.sendBroadcast(i);
}