I am using AudioManager in order to make this work.
This is what I have done:
private AudioManager isPlaying = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
if(isPlaying.isMusicActive()) {
isPlaying.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
} else{
Toast.makeText(getApplicationContext() , "There is no music playing..", Toast.LENGTH_SHORT).show();
}
I want to stop the music playing from youtube or any other app. In addition, how can I pause it and resume it?