Let iOS fade out audio

When sending the game to background on iOS, the sound is immediately cut instead of letting the system fade it out as it does by default.

I then noticed that there’s code specifically doing that in the RuntimeManager in the Unity integration via OnApplicationFocus. When I comment out the whole function everything works as expected. This leaves me puzzled though why the function exists in the first place?

Is there a reason why I have to/ should call lowlevelSystem.mixerSuspend() because to me it seems everything works fine if I don’t.

Kind regards,
Jan

It depends on the AudioCategory used for the app, but we added the Suspend/Resume to OnApplicationFocus for Handling Interruptions.

OK, I don’t fully understand the implications of your answer:

It depends on the AudioCategory used for the app

Why does that mean, and how would I change/ influence that category? Are you referring to the Audio technologies listed here?
https://developer.apple.com/library/archive/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/HandlingAudioInterruptions/HandlingAudioInterruptions.html#//apple_ref/doc/uid/TP40007875-CH4-SW4

we added the Suspend/Resume to OnApplicationFocus for Handling Interruptions.

When I delete the lines of code in the RuntimeHandler, Audio behaves as I expect it – the sound gets faded out by the system, when I switch back to the app again, it starts and AFAICT everything works as expected.
In contrast, when I leave the implemntation in OnApplicationFocus in the game, it cuts off audio apprupt, causing chopped sounds to be heard.
So my question is, is there any downside to not call mixerSuspend/ mixerResume? Are there any implications that can’t be heard (regarding internal resource management, etc.)?

You can change the “Behavior in Background” in the Player settings in Unity, I believe Unity uses this to set the AudioCategory.

FMOD will not be allowed, by the OS, to run in the background and can cause deadlocks if the AudioCategory is not set up correctly.

There is no special configuration inside FMOD required to enable the playback of audio from the lock screen or the background, there are two things you must configure outside of FMOD to do this though.

  1. Choose an AudioSession category that supports background / lock screen audio, see audio session basics for more details.
  2. Enable background audio functionality in your info.plist with the UIBackgroundModes key, see the iOS key reference for more details.

When playing audio on the lock screen (or during the fade out transition to silence when locking) it is important to ensure your buffering is configured correctly to allow low power audio playback. Please consult the latency section of this doc for further details.

If you remove the calls to mixerPause/Resume FMOD will continue to run and process audio in the background which, if configured properly, won’t be an issue.