3

这是我在 iOS 应用程序中遇到的一个奇怪的声音问题。

由于我的代码在大约 90% 的时间内都可以正常工作,因此重现错误并不容易。

但是问题似乎(偶尔)在录音结束时发生。当我手动停止录制或自动停止时。

在调试器下,我看到程序中与插入/拔出耳机相关的某个点出现了崩溃。实际上没有插入耳机,我根本没有插入或拔出任何耳机。

我在程序中的某个时间点有这段代码:

AudioSessionPropertyID routeChangeID=kAudioSessionProperty_AudioRouteChange;
AudioSessionAddPropertyListener(routeChangeID,svcHandleRouteChange,(__bridge void *)(self));

和这个:

void svcHandleRouteChange(void *inUserData,AudioSessionPropertyID inPropertyID,
                          UInt32 inPropertyValueSize,const void *inPropertyValue)
{
    CFStringRef route;
    UInt32 propertySize=sizeof(CFStringRef);
    if (AudioSessionGetProperty(kAudioSessionProperty_AudioRoute,&propertySize,&route)==0)  {
        NSString *routeString = (__bridge NSString *) route;
        if ([routeString isEqualToString: @"Headphone"]) {
            // A headphone is now plugged in.
            // We do nothing.
        } else if ([routeString isEqualToString: @"Speaker"]) {
            // No headphone is plugged in. The device is using the speaker.
            LocalViewController* this=(__bridge LocalViewController*)inUserData;

            //[this->audioPlayer pause]; // The private variable audioPlayer could be accessed like this.
            [this headPhoneOut];
        } else {
            // This should not happen!!
        }
    }
}

崩溃发生在以下行: LocalViewController* this=(__bridge LocalViewController*)inUserData;

最后,这是我在崩溃后进入调试器的回溯,以防有人给我提示:

(lldb) bt
* thread #5: tid = 0x292d8, 0x3abba0ec libobjc.A.dylib`objc_retain + 12, stop reason = EXC_BAD_ACCESS (code=1, address=0x6e966a29)
    frame #0: 0x3abba0ec libobjc.A.dylib`objc_retain + 12
    frame #1: 0x000eb7d6 parl100`svcHandleRouteChange(inUserData=0x14e5f190, inPropertyID=1919902568, inPropertyValueSize=4, inPropertyValue=0x14f0b120) + 182 at LocalViewController.m:801
    frame #2: 0x301ae944 AudioToolbox`AudioSessionPropertyListeners::CallPropertyListenersImp(unsigned long, unsigned long, void const*) + 684
    frame #3: 0x301ae456 AudioToolbox`AudioSessionPropertyListeners::CallPropertyListeners(unsigned long, unsigned long, void const*) + 334
    frame #4: 0x301aee90 AudioToolbox`HandleCFPropertyListChange(unsigned int, unsigned long, unsigned char*, unsigned int) + 412
    frame #5: 0x301aec7e AudioToolbox`HandleAudioSessionPropertyChangedBlobListenerMessage(unsigned int, void*, unsigned int) + 206
    frame #6: 0x301aeb0e AudioToolbox`ASCallbackReceiver_AudioSessionPropertyChangedBlobListenerMessage + 178
    frame #7: 0x301aea3e AudioToolbox`_XAudioSessionPropertyChangedBlobListenerMessage + 94
    frame #8: 0x301ae088 AudioToolbox`mshMIGPerform + 124
    frame #9: 0x308dc9e6 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
    frame #10: 0x308dc982 CoreFoundation`__CFRunLoopDoSource1 + 346
    frame #11: 0x308db156 CoreFoundation`__CFRunLoopRun + 1398
    frame #12: 0x30845ce6 CoreFoundation`CFRunLoopRunSpecific + 522
    frame #13: 0x30845aca CoreFoundation`CFRunLoopRunInMode + 106
    frame #14: 0x2f837588 libAVFAudio.dylib`GenericRunLoopThread::Entry(void*) + 128
    frame #15: 0x2f82ba96 libAVFAudio.dylib`CAPThread::Entry(CAPThread*) + 178
    frame #16: 0x3b1e4c1c libsystem_pthread.dylib`_pthread_body + 140
    frame #17: 0x3b1e4b8e libsystem_pthread.dylib`_pthread_start + 102
(lldb) 

这是第二种情况,同样的问题发生在应用程序的不同点:

2013-10-23 12:25:12.135 parl100[1532:60b] audioRecorderDidFinishRecording
(lldb) bt
* thread #5: tid = 0x2b37a, 0x3abba0ec libobjc.A.dylib`objc_retain + 12, stop reason = EXC_BAD_ACCESS (code=1, address=0xd0003511)
    frame #0: 0x3abba0ec libobjc.A.dylib`objc_retain + 12
    frame #1: 0x000f18a2 parl100`cvcHandleRouteChange(inUserData=0x176b5610, inPropertyID=1919902568, inPropertyValueSize=4, inPropertyValue=0x1762d660) + 182 at ZapViewController.m:566
    frame #2: 0x301ae944 AudioToolbox`AudioSessionPropertyListeners::CallPropertyListenersImp(unsigned long, unsigned long, void const*) + 684
    frame #3: 0x301ae456 AudioToolbox`AudioSessionPropertyListeners::CallPropertyListeners(unsigned long, unsigned long, void const*) + 334
    frame #4: 0x301aee90 AudioToolbox`HandleCFPropertyListChange(unsigned int, unsigned long, unsigned char*, unsigned int) + 412
    frame #5: 0x301aec7e AudioToolbox`HandleAudioSessionPropertyChangedBlobListenerMessage(unsigned int, void*, unsigned int) + 206
    frame #6: 0x301aeb0e AudioToolbox`ASCallbackReceiver_AudioSessionPropertyChangedBlobListenerMessage + 178
    frame #7: 0x301aea3e AudioToolbox`_XAudioSessionPropertyChangedBlobListenerMessage + 94
    frame #8: 0x301ae088 AudioToolbox`mshMIGPerform + 124
    frame #9: 0x308dc9e6 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
    frame #10: 0x308dc982 CoreFoundation`__CFRunLoopDoSource1 + 346
    frame #11: 0x308db156 CoreFoundation`__CFRunLoopRun + 1398
    frame #12: 0x30845ce6 CoreFoundation`CFRunLoopRunSpecific + 522
    frame #13: 0x30845aca CoreFoundation`CFRunLoopRunInMode + 106
    frame #14: 0x2f837588 libAVFAudio.dylib`GenericRunLoopThread::Entry(void*) + 128
    frame #15: 0x2f82ba96 libAVFAudio.dylib`CAPThread::Entry(CAPThread*) + 178
    frame #16: 0x3b1e4c1c libsystem_pthread.dylib`_pthread_body + 140
    frame #17: 0x3b1e4b8e libsystem_pthread.dylib`_pthread_start + 102
(lldb) 

如有必要,我可以提供更多代码。告诉我我应该包括什么。

我希望有人能指出我不能以正确的方式做的事情。

4

0 回答 0