我有一个带有基本音频组件的应用程序:使用AVAudioPlayer播放的一组循环背景歌曲(歌曲文件名存储为数组)。一切都运作良好已经好几个月了,但是iOS 10对我的大量用户(每天数千人)会出现崩溃。
问题是,我无法确定iOS 10发生了什么变化。似乎每次用户锁定设备时都会发生,并且特别是在音乐淡出完成后立即发生(它不执行后台音频,因此离开应用程序会自动淡出音乐)。
在那一刻,我每次都会得到以下信息:
2016-09-22 17:06:39.439979 TerraGenesis[8533:2459778] [aurioc] 889: failed: '!pla' (enable 2, outf< 2 ch, 0 Hz, Float32, non-inter> inf< 2 ch, 0 Hz, Float32, non-inter>)
2016-09-22 17:06:39.443348 TerraGenesis[8533:2459778] [aurioc] 889: failed: '!pla' (enable 2, outf< 2 ch, 44100 Hz, Float32, non-inter> inf< 2 ch, 0 Hz, Float32, non-inter>)
2016-09-22 17:06:39.445339 TerraGenesis[8533:2459778] [central] 54: ERROR: [0x1b50d6c40] >avae> AVAudioEngineGraph.mm:2515: PerformCommand: error 561015905
2016-09-22 17:06:39.446646 TerraGenesis[8533:2459778] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'error 561015905'
*** First throw call stack:
(0x1904781c0 0x18eeb055c 0x190478094 0x1a99d978c 0x1a99ed170 0x1a99ede58 0x1a9a5b3a0 0x1a9a5a6b0 0x1a9a5a640 0x1a0228580 0x1a020cff8 0x19041222c 0x190411930 0x1904116ac 0x190480b9c 0x190353bf4 0x190e5a6bc 0x1963284a0 0x19654df40 0x19655c3ec 0x196547ae8 0x19654776c 0x196879034 0x191febbd4 0x192019904 0x192019770 0x192019b18 0x190426278 0x190425bc0 0x1904237c0 0x190352048 0x191dd5198 0x19632b818 0x196326550 0x1001c1428 0x18f3345b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
这是堆栈跟踪:
Fatal Exception: com.apple.coreaudio.avfaudio
0 CoreFoundation 0x18d45c1c0 __exceptionPreprocess
1 libobjc.A.dylib 0x18be9455c objc_exception_throw
2 CoreFoundation 0x18d45c094 +[NSException raise:format:]
3 AVFAudio 0x1a6a7578c AVAE_RaiseException(NSString*, ...)
4 AVFAudio 0x1a6a89170 AVAudioEngineGraph::PerformCommand(AUGraphNode&, AVAudioEngineGraph::ENodeCommand, void*, unsigned int) const
5 AVFAudio 0x1a6a89e58 AVAudioEngineGraph::Initialize()
6 AVFAudio 0x1a6af73a0 AVAudioEngineImpl::Initialize()
7 AVFAudio 0x1a6af66b0 AVAudioEngineImpl::Start(NSError**)
8 AVFAudio 0x1a6af6640 -[AVAudioEngine startAndReturnError:]
9 SceneKit 0x19d20c580 CPP3DAudioEngine::GetAVEngine()
10 SceneKit 0x19d1f0ff8 -[SCNView _enterBackground:]
这里是我的代码。这是我代码中唯一处理音频的部分。
-(void)playNextSong {
int musicPlaybackIndex = [[[NSUserDefaults standardUserDefaults] objectForKey:@"musicPlaybackIndex"] intValue];
NSURL *soundFileURL = [NSURL fileURLWithPath:[_musicPlaylist objectAtIndex:musicPlaybackIndex]];
_musicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
_musicPlayer.volume = 0.15;
_musicPlayer.delegate = self;
[_musicPlayer prepareToPlay];
[_musicPlayer play];
if(musicPlaybackIndex+1 < [_musicPlaylist count]) {
musicPlaybackIndex++;
} else {
musicPlaybackIndex = 0;
}
}
我在iPhone、iPad和iPod touch上看到了这个崩溃,但是只在iOS 10.0.0和10.0.1上看到。我已经搜索了几个小时关于"[aurioc]"的调用,但是找不到有用的信息,并且它使用了我无法理解的行话。
有人能否告诉我我可能做错了什么,或者帮助我指出AVAudioPlayer在iOS 10中可能发生了什么变化?