I have this code, which seems to be pretty standard when it comes to play sound in an iOS app.
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"click"
ofType:@"wav"]];
NSError *error;
self._audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:url
error:&error];
if (error)
{
NSLog(@"Error in audioPlayer: %@",
[error localizedDescription]);
} else {
self._audioPlayer.delegate = self;
[self._audioPlayer prepareToPlay];
[self._audioPlayer play];
}
it works absolutely fine on the device.
On the simulator however, it doesn't play anything, just print this error message (which is caught somewhere at a low level as the app doesn't crash).
2014-05-14 18:10:46.121 sample_app[7684:14303] 18:10:46.121 ERROR: 189: EXCEPTION thrown ('fmt?'): -
(this error can be printed many times)
when debugging, everything looks OK, the nserror stays nil, url is valid, etc.
audioPlayerDidFinishPlaying:successfully: is event called with 1.
Anybody has had the same issue or has a suggestion regarding what's wrong with my environment?
Many Thanks
I had this same problem, and found a strange solution. Try this:
Don't know why this works, must be a simulator bug. If you make these changes while the simulator is running, you'll notice a log message pop up in Xcode warning you to restart the simulator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With