may help you . You have to use a foreground Service for this. The probability that a background Activity or a background Service gets killed by Android is very high. This is the problem you observe.
Music stops playing on certain devices and keeps playing on others
will be helpful for those in need Most likely your problem is with audio focus. On certain system, when user go to the dashboard, the launcher might take audio focus (and pause your audio play) to play its launch sound (the clicking noise or w/e). Right after that, it should hand back audio focus to you and you will need to resume your playing. http://developer.android.com/training/managing-audio/audio-focus.html
JavaFX MediaPlayer playing background music loop with small intro music
I wish this help you After experience with other well-known game engines (e.g. Unity), I found that the files should be in .wav format as opposed to .mp3 format. This will allow the music to be looped seamlessly.
How to make notification dismissible when playing music in background like in Spotify and Google Music
around this issue I think you can have a timer in your service that restarts your service after a while if the user stopped the music your timer will keep it from dying and if the user clicked play button do as what you already do before.