ObjectAL automatic interruption handling error

a 夏天 提交于 2019-12-12 07:52:58

问题


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 ?

来源:https://stackoverflow.com/questions/32510684/objectal-automatic-interruption-handling-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!