0

I am using Android 5.0 and 6.0. I want to check my default media player (calls from intent) is running/playing in background. Currently, I used the function

AudioManager mAudioManager = (AudioManager) getSystemService(getApplicationContext().AUDIO_SERVICE);
if(mAudioManager.isMusicActive()){
    Log.d("TAG","Running");
}
else{
    Log.d("TAG","Not running");
}

However, it cannot know if the media player is in background but it is in stop/pause mode (looks like when you scroll down the notification bar and click the pause button in the media player). Do we have any function which can determine the media player is opened in background, but it is in stop/pause mode?

enter image description here

user3051460
  • 1,455
  • 22
  • 58
  • I don't even think that's reliable as you can make a music player without using AudioManager. – DeeV Dec 05 '16 at 15:50
  • Sorry. I did not fully understand what you said. I am using default media player by using intent `Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER); try { startActivity(intent); } catch ( Exception e ) { e.printStackTrace(); }` – user3051460 Dec 05 '16 at 15:54
  • When a music opened, I return the Home screen. Now the media player is running in background. I can use the `isMusicActive()` function to check the media player playing or stopping. However, the function cannot check the state such as media player is openning in background but it is in pause/stopping mode. It looks like when you open notification bar and press the pause button in media player, the `isMusicActive()` returns the false, although media player does not close – user3051460 Dec 05 '16 at 16:01
  • Do you only care about the default phone media player or other ones like Google Music, Amazon Music, or VLC? I'm saying that third party apps could technically make their own audio players without using the AudioManager for anything but focus. – DeeV Dec 05 '16 at 16:15
  • @user3051460 apparently, if isMusicActive() returns false, no app is using STREAM_MUSIC, though it may be running in idle state. I don't get why would you want to care about other apps state. – Yaroslav Mytkalyk Dec 05 '16 at 16:46
  • @DeeV: Sorry for reply late. I just focus in media phone player only. Other music app will not consider. Yaroslav Mytkalky: You right. At that false state, the music app may be still open in background but it in pause mode. I want to detect it. Because I want to make a controller to control media player. When it is open in background and in pause state. I want to play it – user3051460 Dec 06 '16 at 02:13

0 Answers0