I have a client that wants their game on WebGL and supporting on mobile with default browsers which includes Safari on iOS devices. We pause the audio mixer when going to other tabs to prevent audio between them and resume when focus returns. The issue is that when going to a separate app it needs to recreate the audio context to be able to play audio again. When doing so it will restart the audio instead of resuming it.
private void OnApplicationFocus (bool focus)
{
if (RuntimeManager.StudioSystem.isValid ())
{
RuntimeManager.PauseAllEvents (!focus);
if (!focus)
{
RuntimeManager.CoreSystem.mixerSuspend ();
}
else
{
RuntimeManager.CoreSystem.mixerResume ();
//Added this to force start the audio on Safari mobile
if (hasInstance)
{
currentInstance.start ();
}
}
}
}
////....////
//setup code
currentInstance = RuntimeManager.CreateInstance(MusicEventPath);
selfHandle = GCHandle.Alloc(this, GCHandleType.Weak);
currentInstance.setUserData(GCHandle.ToIntPtr(selfHandle));
currentInstance.setCallback(MarkerCallback, EVENT_CALLBACK_TYPE.TIMELINE_MARKER);
currentInstance.start();
hasInstance = true;
//////
Is there a way to have the audio resume properly?