I had the same problem and decided ugly: there is a global static player. in onPause activity, it calls the player to stop (but it does not actually stop), and in onResume call to start. In onStart Player, I mark music as a game. In onStop, I mark music as stopped, but I don't actually stop it. I wake up 1 second after the stop was called, and if there was no “startPlaying” at the last second, I stop the music.
I hope there is a better way.
source share