崩溃:iOS中的AVAudioSession通知线程

Vin*_*ose 5 objective-c interrupt-handling audiotoolbox ios avplayer

我正在AudioToolBox中发生EXC_BAD_ACCESS崩溃。如何正确处理中断?

请查看crashlytics屏幕截图以获取更多信息。 crashlytics屏幕截图

Vin*_*ose 3

当我接到电话/faceTime 时,我的音频流播放器崩溃了。它实际上是一个非 ARC 的较旧的类。只需为流类添加一个 InterruptionNotification Observer,如果流类正在播放,我们需要在中断开始时暂停播放器实例。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruptionChangeToState:) name:@"ASAudioSessionInterruptionOccuredNotification" object:nil];

- (void)handleInterruptionChangeToState:(NSNotification *)notification {
AudioQueuePropertyID inInterruptionState = (AudioQueuePropertyID) [notification.object unsignedIntValue];
if (inInterruptionState == kAudioSessionBeginInterruption){
    if ([self isPlaying]) {
        [self pause];

        pausedByInterruption = YES; //a global Bool variable
    }
}
else if (inInterruptionState == kAudioSessionEndInterruption){
    AudioSessionSetActive( true );
    if ([self isPaused] && pausedByInterruption) {
        [self pause]; // this is actually resume
        pausedByInterruption = NO;
    }
}
Run Code Online (Sandbox Code Playgroud)

}

希望能帮助到你。