iOS sounds not working after watching an ad in Safari

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