[英]how to solve run time error of The operation couldn’t be completed. (OSStatus error -43.)?
I am beginner of iPhone. 我是iPhone的初学者。 I want to play audio.for that purpose I have used AVAudioPlayer.. but that object return null value.. and also give run time error of The operation couldn't be completed.
我想播放音频。为此,我使用了AVAudioPlayer ..但该对象返回null值。并且还给出了无法完成操作的运行时错误。 (OSStatus error -43.)
(OSStatus错误-43。)
This is the code I used 这是我使用的代码
-(IBAction)sound
{
NSError *error;
int currentsound;
path=[[NSBundle mainBundle] pathForResource:@"Animalfile" ofType:@"plist"];
dict=[NSDictionary dictionaryWithContentsOfFile:path];
animalaudio=[dict valueForKey:@"audio"];
NSLog(@"print:%@",dict);
NSLog(@"printanimal%@",animalaudio);
audiolist=[animalaudio objectAtIndex:currentsound];
NSLog(@"audiolist:%@",audiolist);
url=[NSURL fileURLWithPath:audiolist];
NSLog(@"url:%@",url);
audioplayer=[[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
NSLog(@"audioplayer:%@",audioplayer);
if( audioplayer == nil ){
NSLog(@"Failed with reason: %@", [error localizedDescription]);
}
else{
[audioplayer play];
}
}
in that url also return the mp3 file but why url not pass in AVAudioPlayer because of audioplayer return the null but not return mp3 file.so, which code I write in AVAudioPlayer?give any suggestion and source code.... 在该网址中还返回了mp3文件,但为什么由于音频播放器而未在AVAudioPlayer中传递该网址,但返回了null但未返回mp3文件,所以我在AVAudioPlayer中编写了哪些代码?给出任何建议和源代码....
path=[[NSBundle mainBundle] pathForResource:@"Animalfile" ofType:@"plist"];
path must be a single file not a plist 路径必须是单个文件而不是plist
try to give the path one value 尝试给路径一个值
Example: 例:
path = [[NSString alloc] initWithFormat:[[NSBundle mainBundle] pathForResource:@"firstTrack" ofType:@"mp3"]]
-43 is a File not found error Check that the relative file path in your plist can be found from the working directory. -43是“找不到文件”错误检查是否可以从工作目录中找到plist中的相对文件路径。 Or better, use one of the many resource-finding methods of NSBundle to find your sound file directly, you will then get an existing absolute path.
或者更好的方法是,使用NSBundle的许多资源查找方法之一直接找到您的声音文件,然后您将获得一个现有的绝对路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.