iOS sounds not working after watching an ad in Safari

We are developing a game called GnollHack, which uses FMOD as sound middleware. What I’m going to describe is probably some sort of an iOS system problem, but I thought that I ask here just in case someone knows a workaround. The problem is that if I watch an ad with video and sound in Safari (or Chrome), and then start directly our game, the sounds do not play at all. If (1) I start the game, then switch to any other app, and then switch back to the game, or (2) go first to another app, go back to home screen, and only then start the game, the sounds start playing / being audible. Also they become audible if I restart the app. As far as I can see, FMOD is working just fine, but there is just no audio, which may be some sort of an audio session problem. AVAudioSessionCategory is ambient, but the same problems occur also with playback. Any of the settings or modes I have tried do not seem to make a difference.

Any ideas how to force the audio to be audible immediately after watching ads in Safari would be appreciated. This is a problem only with iOS and only if I watch first ads in a browser (another app like Safari or Chrome) that contain video and sound immediately prior to starting the game. This problem appears on all iOS devices we have tested.

Hi,

Thank you for sharing the detailed information.

This sounds similar to an issue discussed here:

I’d recommend giving it a read to see if any of the suggestions apply to your case.

Hope this helps!

Hi, I finally got around to working on this more. The problem got finally fixed by changing the DSP Buffer Length in coresystem to 1024 BEFORE calling system.initialize as follows:


#if IOS

        int numBuffers;
        uint bufferLength;
        res = _coresystem.getDSPBufferSize(out bufferLength, out numBuffers);

        if (res == RESULT.OK && bufferLength != 1024)
            res = _coresystem.setDSPBufferSize(1024, numBuffers);
#endif
        res = _system.initialize(512, FMOD.Studio.INITFLAGS.NORMAL, FMOD.INITFLAGS.NORMAL, IntPtr.Zero);
        if (res != RESULT.OK)
            return;

Althought the latency seems to have now increased to unacceptable levels.

I now implemented the other proposed fix, and it seems to solve the issue without increasing latency. Also, SoloAmbient category didn’t seem to do anything for me, so I kept the category at Ambient as before. So the final solution to the problem (using .NET for iOS bindings) is as follows for me (SetCategory and SetActive were there before):

        _coresystem.getSoftwareFormat(out int systemSampleRate, out _, out _);
        _coresystem.getDSPBufferSize(out uint systemDSPBufferLength, out _);
        SetAudioSessionSettings(systemSampleRate, systemDSPBufferLength);

        private void SetAudioSessionSettings(double rate, double blockSize)
        {
#if IOS
            AVAudioSession si = AVAudioSession.SharedInstance();
            if (si != null)
            {
                Debug.WriteLine("SetAudioSessionSettings: rate is " + rate + ", blockSize is " + blockSize);
                try
                {
                    NSError audioSessionError;
                    double bufferDuration = blockSize / rate;
                    si.SetPreferredIOBufferDuration(bufferDuration, out audioSessionError);
                    si.SetPreferredSampleRate(rate, out audioSessionError);
                    si.SetCategory(AVAudioSessionCategory.Ambient);
                    si.SetActive(true);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Exception occurred with AVAudioSession: " + ex.Message);
                }
            }
#endif
        }

1 Like

Glad to hear the issue is resolved, and thanks for sharing the solution here!