I've been playing with phone calls while (SpriteKit)game running in order to test interruptions. I am using example from ObjectAL documentation called : "Using the OpenAL Objects and OALAudioTrack".
So, I let the library to handle this automatically...
[OALAudioSession sharedInstance ]. handleInterruptions = YES
And it works but partially. For example, with simple setup with 3 sounds I get next error message :
OALAudioSession activateAudioSession]: Could not activate audio session after 2 tries: Error Domain=NSOSStatusErrorDomain Code=561015905 "The operation couldn’t be completed. (OSStatus error 561015905.)"
Error 561015905 == 0x21706C61 == !pla
, and referring to error declared in AVAudioSession.h:
AVAudioSessionErrorCodeCannotStartPlaying = '!pla', /* 0x21706C61, 561015905
And actually this works, there are two failed attempts, third was successful, nothing can be noticed because everything is fast and everything seems to be working as it should.
I've noticed that if I add more sounds (lets say 20) , I will get same messages:
Could not activate audio session after 20 tries:
After that, the session is activated. Then, I just added debugging message in relevant 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 tries, I get message which says : "Session activated after 21 tries"
But because kMaxSessionActivationRetries is set to 40, eventually sound playing will "break" because the number of tries can easily go above those allowed 40 attempts. I am aware that I can change this value, but that doesn't actually solve the problem.
Am I missing something important here ? I thought that when handleInterruptions
property is set to YES , we don't have to do any manual interruptions/session handling ? I am testing on iPhone 6 & iOS8 if that matters. Could anyone shed some light on this ?