5

I am getting EXC_BAD_ACCESS crash that occurs in the AudioToolBox. How to handle interrupts properly?

Please have a look at crashlytics screenshot for more info. crashlytics screenshot

Vinu David Jose
  • 2,569
  • 1
  • 21
  • 38

1 Answers1

3

My audio streaming player was crashing when I get a phone call/ faceTime. It was actually an older class with Non ARC. Simply Add an InterruptionNotification Observer for the streaming class, and if the streaming class is playing we need to pause the player instance while interrupt begins.

[[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;
    }
}

}

Hope it helps.

Vinu David Jose
  • 2,569
  • 1
  • 21
  • 38