App crashes with AVAudioSession privateBeginInterruption

I’m testing my app on device (a soundboard) and it crashes with a EXC_BAD_ACCESS, I have use Breakpoints and the error came from [AVAudioSession privateBeginInterruption]

The crash happens following this pattern:

  • Swift: how to set the iphone volume programmatically
  • iOS background audio not playing
  • AVAudioPlayer is always nill and its isPlaying property is always false. The files are mixed while playing
  • AudioSession input from bluetooth output to line out or speaker
  • AVAudioSession setCategory not working
  • How can you play a sound of a specified duration using AVAudioPlayer on iOS?
    1. The app is launched, we see the main menu
    2. A main menu button is pressed and a soundboard view is loaded (push), some buttons are pressed here and sounds are played.
    3. Return to main menu ([self.navigationController popViewControllerAnimated:YES];)
    4. App enters background
    5. When app enters foreground and the menu button of the soundboard is pressed the app crashes.

    I have no idea what is happening here, I have installed CrashLytics and it only said:

    app crash

    Maybe the audio session gets released from memory and the app tries to access to it and fail?

    The audio session is initialised in viewDidLoad

    //  Initialize audio session
    [[AVAudioSession sharedInstance] setDelegate: self];
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error: nil];
    
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof    (audioRouteOverride),&audioRouteOverride);  
    

    In viewDidUnload I have

    [[AVAudioSession sharedInstance] setDelegate: nil];
    

    Any hints?

    Thanks!

    Solutions Collect From Internet About “App crashes with AVAudioSession privateBeginInterruption”

    The crash happens because you had set the delegate of session to your controller in this line

    [[AVAudioSession sharedInstance] setDelegate: self];
    

    but didn’t implemented the required delegate method (interruption one)

    either remove the delegate setting line or implement the delegate method to solve crash