I am trying to pause sounds when ads are playing. I am using Appslovin Max SDK for ads.
Sounds should not play when ads are playing.
FMOD will not automatically stop playing audio when interrupted by other software like ad integrations.
RuntimeManager.CoreSystem.mixerSuspend();
should be called when an ad starts playing, and RuntimeManager.CoreSystem.mixerResume();
when an ad stops playing and you want FMOD audio to return. You may need to call this manually from your own code when you start/stop playing an ad, or Appslovin Max SDK may offer callbacks for you to tie the suspend and resume calls to.
#if (UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS) && !UNITY_EDITOR
[AOT.MonoPInvokeCallback(typeof(Action<bool>))]
private static void HandleInterrupt(bool began)
{
if (Instance.studioSystem.isValid())
{
// Strings bank is always loaded
if (Instance.loadedBanks.Count > 1)
PauseAllEvents(began);
if (began)
{
Instance.coreSystem.mixerSuspend();
}
else
{
Instance.coreSystem.mixerResume();
}
}
}
#if (UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS) && !UNITY_EDITOR
[DllImport(“__Internal”)]
private static extern void RegisterSuspendCallback(Action func);
#endif
Allow this code in runtimemanager to be done automatically?
The code in RuntimeManager that you’ve linked cannot be done automatically.
For iOS system suspend/resume, we specifically subscribe to a number of iOS system notifications that we use to call the HandleInterrupt()
function that you’ve pointed out - the code for this can be found at ./Assets/Plugins/FMOD/platform_ios.mm
.
This works fine for system interruptions, but since ad integrations use their own interruptions, if you need to suspend and resume FMOD audio you’re required to handle mixerSuspend()
/mixerResume()
yourself. Modifying RuntimeManager()
to make use of the existing code in some way would be one method of doing this.