iOS audio session interruption

When a timer goes of or a call comes in on iOS, the game automatically mutes, but doesn’t unmute until manually tabbing in and out. I’ve looked at the mixerSuspend and mixerResume functions, and they are being called on OnApplicationPaused already in the FMODRuntimeManager - this should be a very common scenario, do you have any guidelines on how to achieve this in UNITY ? I’ve seen the iOS specific guide but how can I add a listener for the AVAudioSessionInterruptionNotification?
Neither OnApplicationPause nor OnApplicationFocus are triggered on interruptions…

Thank you!

Is there a method I can use to at least perform polling, and check whether the mixer can be resumed ?

What versions of FMOD and Unity are you using?

Unity 2019.2.3 ( also tested in unity 2019.1.8) and FMOD Unity integration V 1.10.15 ( tried 1.10.9 previously ) It is actually only happening for timers/alarms - calls where fine on my last test.
EDIT: Tested on iOS12 and iOS13 Beta

I just tested Unity 2019.1.8 using FMOD 1.10.15 and it worked for calls, timers and alarms just fine.

Are you getting anything in the logs? You may need to change the ‘Logging Level’ in the FMOD Unity Settings to LOG to get more information.

I’m not getting anything in the logs. I had mine set to Warning, I will change it and test again. Does it fire OnApplicationFocus for you when alarm pop up comes in ? Is that supposed to fire?

FMOD Studio: Device iPhone9,3 classed as MobileHigh

FMODUnity.RuntimeUtils:GetCurrentPlatform()

FMODUnity.RuntimeManager:Initialize()

FMODUnity.RuntimeManager:get_Instance()

FMODUnity.RuntimeManager:get_StudioSystem()

FMODUnity.RuntimeManager:GetBus(String)

I’m just getting these initialisation logs at start up, and no logs whatsoever after that with logging set to LOG.

What I do is:
Set Alarm to 10 seconds, go back into the game, swipe the alarm banner away ( don’t click on it ) Audio will stop, no logs.

Currently testing with Unity 2019.2.3, XCode 10.3 and Xcode 11 on iOS 12 and iOS 13, iPhone SE, 2 different iPads and iPhone 7 - Same issues reproducible everywhere for me.

Ah yes, I was able to reproduce this. I was dismissing the notification differently which was causing the sound to come back.

It looks like what is happen is the OS is muting the game when it gets the notification, but then doesn’t un-mute it when the notification stops. The system does trigger a ‘AVAudioSessionInterruptionNotification’ when the notification starts and finishes but this does not appear to trigger Unity’s OnApplicationFocus.

Glad you managed to reproduce it, I was about to create an empty project and send that along.
No way around writing my own native plugin to fix this then? Thank you

It seems like it may be a bug in Unity, unless there is another way that they expect you to use the AVAudioSessionInterruptionNotification from C#.

Just implemented the plugin, but it still won’t work, the audio doesn’t come back.
I have an issue on tvOS as well where the audio sporadically just won’t work, and calling mixerResume or unPause won’t have any effect, only way to get the audio back is minimizing and unminimizing the app. ( both for this issue and the tvOS issue)

public void AudioInterruptionEvent(string message){
    Debug.Log("AUDIO INTERUPT EVENT, message: "+message);
    if(message == "Began"){
        Debug.Log("FMOD Suspending...");
        FMODUnity.RuntimeManager.PauseAllEvents(true);
        fmodSystem.mixerSuspend();
    }
    if(message == "Finished"){
        FMODUnity.RuntimeManager.PauseAllEvents(false);
        fmodSystem.mixerResume();
    }
}

mixerResume won’t do anything if mixerSuspend has not been called before hand. Depending on how the app has interrupted it may not be getting suspended. Add some logging to make sure they are being called and in the order they need to be in.

Mixer suspend is being called I have the debug.log.
Fmod logs(appart from the initialzation) won’t work on iOS/tvOS builds, what do I need to do get them to work?

The FMOD logs should appear in the console, make sure you are using development build and that the logging libs are being used: https://fmod.com/resources/documentation-unity?version=2.0&page=platform-specifics.html#fmod-libs-on-static-platforms. You can also change the logging level in the FMOD settings (LOG should provide the most information): https://fmod.com/resources/documentation-unity?version=2.0&page=settings.html#logging-level.

Thanks cameron. I was missing the static lib step.

So calling mixerSuspend on the AudioInterruption event (or anywhere else, I tried calling it sporadically)
doesn’t create any log or do anything. Pausing all events, effectively pauses all events, but also doesn’t create any log.

I’m using LOG as logging level.

When tabbing in and out however mixerSuspend and mixerResume logs show up correctly. (fired from your RuntimeManager implementation in OnApplicationFocus)

Is the fmodSystem you are using to call mixerSuspend/Resume the same system from FMODUnity.RuntimeManager.CoreSystem or FMODUnity.RuntimeManager.StudioSystem.getCoreSystem.

mixerSuspend/Resume will both return an FMOD.RESULT that will tell you if they fail for some reason.

Native plugin with AVAudioSessionInterruption + marshalling callback does the trick.
UnitySendMessage is async and might have caused some issues here too.

1 Like

Glad to hear you found a solution.

We will look into adding functionality for handling the AVAudioSessionInterruptions in a future release.

hey Cameron,

just thought I’d mention that we’re hoping to see this fix soon too because we’ll probably be affected as well.