简体   繁体   中英

iPhone crash when playing audio file using AVAudioPlayer and incoming call interrupts playback

I have developed an iPhone application which plays different music files. Everything is working fine except when an incoming phone call interrupts the playback. This crashes the app with the following log:

START CRASH LOG

Thread 0 Crashed:

0   libobjc.A.dylib                 0x32d98f20 objc_msgSend + 20
1   AVFoundation                    0x30739ddc AVAudioSessionPropertyListener(void*, unsigned long, unsigned long, void const*) + 284
2   AudioToolbox                    0x36d78bec SSServer_AudioSessionInterruptionListenerMessage + 316
3   AudioToolbox                    0x36d017bc _XAudioSessionInterruptionListenerMessage + 128
4   AudioToolbox                    0x36c68584 mshMIGPerform + 224
5   CoreFoundation                  0x3752f5c4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 22
6   CoreFoundation                  0x3752f582 __CFRunLoopDoSource1 + 158
7   CoreFoundation                  0x3752182e __CFRunLoopRun + 574
8   CoreFoundation                  0x37521504 CFRunLoopRunSpecific + 220
9   CoreFoundation                  0x37521412 CFRunLoopRunInMode + 54
10  GraphicsServices                0x33e76d1c GSEventRunModal + 188
11  UIKit                           0x3591d574 -[UIApplication _run] + 580
12  UIKit                           0x3591a550 UIApplicationMain + 964

END CRASH LOG

I have narrowed it down to a call in the applicationWillResignActive method in the app delegate, but I can't seem to figure it out because if the app goes to background mode (by pressing the home button) the app works correctly, it only crashes when a phone call is received.

The line which causes the crash in the applicationWillResignActive method is:

[navController popToRootViewControllerAnimated:NO]; //navController is an instance of UINavigationController; i used this statement to remove all view controllers and when the app resumes, I push the first view controller so that the app starts from the beginning.

Does anyone have an idea why this crash occurs only when a phone call is received ?

We've just been tracking a very similar crash.

Ours turn out to be as described here:

https://github.com/mattgallagher/AudioStreamer/issues/6

In particular, MyAudioSessionInterruptionListener (or the name of the callback passed to AudioSessionInitialize) and it's inClientData can not be changed after it's been registered, so the callback must always do something sensible even if the underlying object has been deallocated.

The solution suggested for AudioStream is to use a static variable, and make sure it points to the object that is currently interested in the callback, and never points at a deallocated object - the important thing is not to use inClientData.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM