我一直在玩(SpriteKit)游戏时打电话来测试中断.我正在使用ObjectAL文档中的示例:"使用OpenAL对象和OALAudioTrack".
所以,我让图书馆自动处理这个......
[OALAudioSession sharedInstance ]. handleInterruptions = YES
Run Code Online (Sandbox Code Playgroud)
它有效但部分有效.例如,通过3声音的简单设置,我得到下一条错误消息:
OALAudioSession activateAudioSession]:2次尝试后无法激活音频会话:Error Domain = NSOSStatusErrorDomain Code = 561015905"操作无法完成.(OSStatus错误561015905.)"
Error 561015905 == 0x21706C61 == !pla,并引用AVAudioSession.h中声明的错误:
AVAudioSessionErrorCodeCannotStartPlaying ='!pla',/*0x21706C61,561015905
实际上这是有效的,有两次失败的尝试,第三次是成功的,没有什么可以被注意到,因为一切都很快,一切似乎都应该正常工作.
我注意到如果我添加更多声音(比方说20),我会收到相同的消息:
20次尝试后无法激活音频会话:
之后,会话被激活.然后,我刚刚在相关方法中添加了调试消息:
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 …Run Code Online (Sandbox Code Playgroud)