I've got an app with a very basic audio component: a looping set of background songs played with an AVAudioPlayer (song filenames stored as an array). Everything has been working fine for months, but iOS 10 is crashing for a significant number of my users (thousands per day).
The problem is, I can't figure out what's changed in iOS 10. It seems to happen every time the user locks their device, and specifically it happens the instant the music finishes fading out (it doesn't do background audio, so leaving the app automatically fades out the music).
At that moment, I get this every time:
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
Here's the stack trace:
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:]
And here is my code. This is the only part of my code that handles audio in any way.
-(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;
}
}
I'm seeing this crash on iPhones, iPads, and iPod touches, but exclusively on iOS 10.0.0 and 10.0.1. I've been searching for those "[aurioc]" calls for hours now but I can't find anything useful, and it's written in a jargon I can't quite parse.
Can anyone show me what I might be doing wrong, or help point me in the direction of what might have changed with AVAudioPlayer in iOS 10?
This exception with code 561015905 - related to AVAudioSessionErrorCodeCannotStartPlaying. This error type can occur if the app’s Information property list does not permit audio use, or if the app is in the background and using a category which does not allow background audio.
Please take a look at documentation to AVAudioSessionErrorCodeCannotStartPlaying. Hope this help.
This is an Apple bug that has 2 workarounds while we wait for the fix in iOS 10.2:
(1) (worse) enable background audio
(2) (better) see Apple message below
message from Apple: This is a known issue that will be fixed in 10.2. In the meantime another simpler workaround should work: Trigger the audio engine creation yourself before entering the background (for example at setup). You can trigger this simply by getting the audio engine from the SCNView:
scnView.audioEngine;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With