Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  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!

like image 958
roymckrank Avatar asked May 06 '26 06:05

roymckrank


1 Answers

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

like image 193
Shubhank Avatar answered May 08 '26 20:05

Shubhank