崩溃:iOS 中的 AVAudioSession 通知线程
Crashed: AVAudioSession Notify Thread in iOS
我在 AudioToolBox 中遇到 EXC_BAD_ACCESS 崩溃。如何正确处理中断?
请查看 crashlytics 屏幕截图以了解更多信息。
当我接到 phone 电话/faceTime 时,我的音频流播放器崩溃了。它实际上是非 ARC 的旧 class。只需为流 class 添加一个 InterruptionNotification Observer,如果流 class 正在播放,我们需要在中断开始时暂停播放器实例。
[[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;
}
}
}
希望对您有所帮助。
我在 AudioToolBox 中遇到 EXC_BAD_ACCESS 崩溃。如何正确处理中断?
请查看 crashlytics 屏幕截图以了解更多信息。
当我接到 phone 电话/faceTime 时,我的音频流播放器崩溃了。它实际上是非 ARC 的旧 class。只需为流 class 添加一个 InterruptionNotification Observer,如果流 class 正在播放,我们需要在中断开始时暂停播放器实例。
[[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;
}
}
}
希望对您有所帮助。