Multitask Audio on resume

Hi,
I’m having issues with my game where audio stops when an app enters the background, but doesn’t resume when it is active again. Anyone know what code or function to use to call code when the program is active again, so i can resume the audio?

Thanks.

Hi,
In Xcode open up the AppController.mm, there’s a method called applicationWillEnterForeground, comment out the following line there (line 821)

pNeedToRestoreIPhoneAudioSession = true;

This is because unity is now using FMOD instead of OpenAL, this hack seems to solve the MultiTask Audio problem, but I’m not sure if it introduces anymore problems or not! I don’t have any problem using this hack I found! But use it on your own as I don’t even know what happens on older devices, iPod touch, etc.

Regards

hey thanks, will test it out.

What I did for mine was the following.
public void OnApplicationPause( bool pause )
{
if(pause)
{
audio.Stop();
}else{
audio.Play();
}
}

@moodiesw
You’re welcome
If you don’t want to mess with Xcode and Object-C go with aiursrage2k’s solution, that’d work as well :wink:

@aiursrage2k
Doesn’t that play the audio from the start?!
I like this one better, of course, it’s not perfectly accurate, but it does its job :wink:

public void OnApplicationPause ( bool pause )
{
     if (pause)
     {
          curTime = audio.time;
     }
     else
     {
          audio.Play();
          audio.time = curTime;
     }
}

Regards

Hey thanks guys, final solution looks perfect. Exactly what i needed, especially with the time setting. Thanks so much for the help.