I play with phone calls while (SpriteKit) is working to check for interruptions. I use an example from the ObjectAL documentation: "Using OpenAL and OALAudioTrack Objects" .
So, I let the library handle this automatically ...
[OALAudioSession sharedInstance ]. handleInterruptions = YES
And it works, but partially. For example, with a simple setup with three sounds, I get the following error message:
OALAudioSession activateAudioSession]: Failed to activate the audio session after 2 attempts: Domain error = NSOSStatusErrorDomain Code = 561015905 "Operation could not be completed. (OSStatus Error 561015905.)"
Error 561015905 == 0x21706C61 == !pla and referring to the error declared in AVAudioSession.h:
AVAudioSessionErrorCodeCannotStartPlaying = '! pla ', / * 0x21706C61, 561015905
And actually it works, there are two unsuccessful attempts, the third was successful, nothing can be noticed, because everything is fast and everything seems to work as it should.
I noticed that if I add more sounds (say 20), I will get the same messages:
Failed to activate audio session after 20 attempts:
After that, the session is activated. Then I just added a debug message in the appropriate method:
OALAudioSession.m
- (void) activateAudioSession { NSError* error; for(int try = 1; try <= kMaxSessionActivationRetries; try++) { if([[AVAudioSession sharedInstance] setActive:YES error:&error]) { NSLog(@"Session activated after %d", try); audioSessionActive = YES; return; } OAL_LOG_ERROR(@"Could not activate audio session after %d tries: %@", try, error); [NSThread sleepForTimeInterval:0.2]; } OAL_LOG_ERROR(@"Failed to activate the audio session"); }
So, finally, after 20 unsuccessful attempts, I get a message that says: "Session activated after 21 attempts"
But since kMaxSessionActivationRetries is set to 40, the sound will ultimately break because the number of attempts can easily go beyond the allowed 40 attempts. I know that I can change this value, but this does not actually solve the problem.
Did I miss something important here? I thought that if the handleInterruptions property handleInterruptions set to YES, we don’t need to do manual interrupts / session processing? I am testing iPhone 6 and iOS8 if that matters. Can anyone shed some light on this?