- Home /
Question by
PawelMarecki · Apr 02, 2017 at 10:01 AM ·
androidactivitybackground music
[Android] Keep music play on standby
Hello! Is this possible to prevent Unity from stop playing music after user click standby button on Android phone?
I've already checked custom activity with a bool flag in onPause()
and onDestroy()
like that:
public boolean isMusicOn = false;
@Override
protected void onPause() {
if (!isMusicOn) super.onPause();
}
@Override
protected void onDestroy() {
if (!isMusicOn) super.onDestroy();
}
public void SetMusic(boolean value) {
isMusicOn = value;
Log.d("LullabyActivity", "SetMusic value: " + value);
}
public boolean DebugGetMusic(){
return isMusicOn;
}
Code compile and is properly executed, but android still force to kill application in moment I try to go to standby or home screen.
I'm using SoundManagerPro from Asset Store as my music manager in project. As far as I know Application.runInBackground
doesn't work on mobiles, so is there a way to keep music play in Unity or I need to write some kind of android service to play audio in background?
I'll be grateful for any suggestions.
Best, Pawel
Comment