iOS 5.0 AVAudioPlayer Error loading audio clip: The operation couldn’t be completed. (OSStatus error -50.)

Posted by Jason Catudal on Stack Overflow See other posts from Stack Overflow or by Jason Catudal
Published on 2012-01-26T16:01:51Z Indexed on 2012/04/14 17:29 UTC
Read the original article Hit count: 626

Filed under:
|
|
|

So I'm trying to test out the audio player on the iPhone, and I went off Troy Brant's iOS book. I have the Core Audio, Core Foundation, AudioToolbox, and AVFoundation frameworks added to my project. The error message I get is in the subject field. I read like 20 pages of Google search results before resorting to asking here! /sigh. Thanks if you can help. Here's my code, pretty much verbatim out of his book:

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Yonah" ofType:@"caf"];
NSLog(@"%@", soundFilePath);
NSURL *fileURL = [NSURL URLWithString:soundFilePath];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];

if (!error)
{
    audioPlayer.delegate = self;
    //audioPlayer.numberOfLoops = -1;
    [audioPlayer play];
}
else
{
    NSLog(@"Error loading audio clip: %@", [error localizedDescription]);
}    

EDIT: Holy Shinto. I figured out what it was. I changed

NSURL *fileURL = [NSURL URLWithString:soundFilePath];

to

NSURL *fileURL = [NSURL fileURLWithPath:soundFilePath];

to the latter and I was getting a weird error, weirder than the one in the subject BUT I googled that and I changed my OS input device from my webcam to my internal microphone and guess what, it worked under the fileURLWithPath method. I'll be. Damned.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ios