AVAudioPlayer crash upon initWithContentsOfURL in macOS, not in iOS ...

Hi there,

I'm trying to figure out what happens with my cross-platform app upon initializing and instance of AVAudioPlayer. The following code works fine in iOS (12.3.1) but crashes at runtine when trying to run initWithContentsOfURL in macOS (10.14.5) : i.e. SIGABRT with the following error: libc++abi.dylib: terminating with uncaught exception of type NSException.

Any idea of what's going on ? Any suggestion or help appreciated.

Best


...

NSURL* soundURL = [self.soundDictionary objectForKey:self.soundPlayingRequest];

if (soundURL != nil) {

NSError *error =nil;

self.soundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error];

soundPlayer.delegate = self;

if (error.description == noErr)

[self.soundPlayer play];

}

Replies

The SIGABRT is the final step of a crash that's actually occurring because a NSException was thrown (and, as normal, not caught). Almost every NSException will put something in the console log when thrown. You should run your app from Xcode and look in the console log pane, or run the Console app and filter on your app's name, and you should see the exception error message (and possibly a backtrace).


Additionally, in Xcode, if you set a general Obj-C exception breakpoint, your app will stop when the exception is thrown (and before its message has been logged), so you can poke around in your code where the error occurred.

Thanks for the comment but I finally fixed this issue. The URL used in the MacOS-specific code was inadequate (and different from the one that succeeded in iOS)

Best


chps67