Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioSessionException on iOS 8.4 #4119

Closed
ebatiano opened this issue Sep 2, 2015 · 5 comments
Closed

AudioSessionException on iOS 8.4 #4119

ebatiano opened this issue Sep 2, 2015 · 5 comments
Labels

Comments

@ebatiano
Copy link

ebatiano commented Sep 2, 2015

When returning from background, sometimes AudioToolbox throws an exception. Here's stack trace (sorry for lack of lines and file names - data is from BugSense):

Exeption: AudioSessionException (Unknown error code: 561015905)
Function: AudioToolbox.AudioSession.SetActive

at AudioToolbox.AudioSession.SetActive (Boolean active) [0x00000] in <filename unknown>:0 
at Microsoft.Xna.Framework.Audio.OpenALSoundController.<OpenSoundController>m__1 (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0 
at AudioToolbox.AudioSession.Interruption (IntPtr userData, UInt32 state) [0x00000] in <filename unknown>:0 
at (wrapper native-to-managed) AudioToolbox.AudioSession:Interruption (intptr,uint) 
@Eversor
Copy link

Eversor commented Oct 1, 2015

Seems fixed on ios9, i have no crashes on that platform for 5 days.

@vchelaru
Copy link
Contributor

vchelaru commented Oct 2, 2015

While this is fixed in iOS 9, it still occurs in iOS 7 and 8, which has a large install base for a while. Any info on why this might be happening?

@vchelaru
Copy link
Contributor

vchelaru commented Oct 2, 2015

I've found somewhat of a workaround. The crash occurs in the AudioSession.SetActive(true) call, as indicated by the previous post.

I played around with it a bit and found out that if I try/catch and consume the exception, the app will continue, but no more audio plays:

            AudioSession.Resumed += (sender, e) => {
                try
                {
                    AudioSession.SetActive(true);
                }
                catch(Exception exce)
                {
             }

Of course that's only a half-solution because it does mean the game is silent until the user relaunches the app. I continued to mess around with it and I found that if I got a crash, I could detect that and delay the re-activation of the Audio Session as follows:

            AudioSession.Resumed += (sender, e) => {
                try
                {
                    AudioSession.SetActive(true);
                }
                catch(Exception exce)
                {
                    try
                    {
                        // maybe we can delay it?
                        System.Threading.Thread.Sleep(1000);
                        AudioSession.SetActive(true);
                    }
                    catch(Exception exce2)
                    {
                        System.Console.WriteLine(exce2.ToString());
                    }
                }
                Alc.MakeContextCurrent(_context);
                Alc.ProcessContext(_context);
            };

Sure enough that solved it, but it does add a delay to the resuming of the app. In my opinion it's a valid workaround because I think a 1 second delay (which maybe could be reduced) is better than a crash which cannot be caught in the game code.

If the powers that be consider this a valid fix to the problem, then I can check it in. To be clear, this issue is only an issue on iOS 7 and 8, so iOS 9 devices should never be impacted by this restart delay, and as they are phased out, this issue will also go away.

Shall I PR it?

Update: 500 milliseconds seems to work on my iPad 3, 250 did not. Hard to say what time we should put in there though as it may depend on device. I'd say 500 - 1000 milliseconds.

@vchelaru vchelaru added the iOS label Oct 2, 2015
@mrhelmut
Copy link
Contributor

mrhelmut commented Oct 3, 2015

Have you tried to monitor the AudioSession's properties with a PropertyListiner to see if something specific may happen and could cause this issue?
AudioSession seems to have been deprecated since iOS 7, so maybe relying on the suggested AVAudioSession may be more reliable (and maybe some events may help knowing when the session can be re-activated).
Active waiting should be avoided, when possible.

@tomspilman
Copy link
Member

This should be fixed now between #4180 and #6433.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants