IOS 5.0 AVAudioPlayer Error loading audio clip: operation could not be completed. (OSStatus error -50.)

So, I'm trying to check the audio player on the iPhone, and I left Troy Brant's iOS book. I have the core modules Core Audio, Core Foundation, AudioToolbox and AVFoundation added to my project. The error message I get is in the subject field. I read how 20 pages of Google search results before starting the assignment here! / Sigh. Thanks if you can help. Here is my code, quite a bit of verbatim from 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: Saint Shinto. I realized what it was. I changed

 NSURL *fileURL = [NSURL URLWithString:soundFilePath]; 

to

 NSURL *fileURL = [NSURL fileURLWithPath:soundFilePath]; 

to the last one, and I was getting a weird error stranger than the one that was in the subject, but I was looking for it, and I changed my OS input device from my webcam to my internal microphone and guessed that it worked according to the fileURLWithPath method . I will. Damned.

+4
source share
2 answers

try this convert your url to NSdata p>

 NSString* resourcePath = self.audioStr; //your url NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePath]]; NSError *error = [[NSError alloc] init]; NSLog(@"url is %@",resourcePath); audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error]; audioPlayer.numberOfLoops = 0; if (error) { NSLog(@"Error in audioPlayer: %@", [error localizedDescription]); } else { audioPlayer.delegate = self; [audioPlayer prepareToPlay]; }` 
+2
source

Try reading an audio file with something like this:

 audioPlayer_ = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:[NSString stringWithString:soundFilePath_]] error:&error]; 
0
source

Source: https://habr.com/ru/post/1393202/


All Articles