当我尝试播放音频时出现此错误
2010-08-27 09:13:40.466 VoiceRecorder [3127:207]原因失败:操作无法完成。 (OSStatus错误-43。)
是什么意思
我正在将文件存储在Iphone Document文件夹中并在我的数据库中复制其名称
所以,当我从数据库中播放它时,它正确获取文件路径
文件和数据库中的文件名称完美但无法播放
2010-08-30 12:22:00.592 VoiceRecorder [8140:207] / Users / Username / Library / Application Support / iPhone Simulator / 4.0.1 / Applications / 4BF0B5C7-59C9-462F-94EC- 662EBCE8505E /文档/ 30Aug10_12_21_58.aif 2010-08-30 12:22:00.593 VoiceRecorder [8140:207] 30Aug10_12_21_58.aif 2010-08-30 12:22:00.618 VoiceRecorder [8140:207]原因失败:操作无法完成。 (OSStatus错误-43。)
需要紧急回复
这是我的代码
-(IBAction)playevent{
VoiceRecorderAppDelegate *appDelegate=(VoiceRecorderAppDelegate*)[[UIApplication sharedApplication]delegate];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *fullpath = [documentsDir stringByAppendingPathComponent:appDelegate.filenamefrompath];
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check if the database has already been created in the users filesystem
BOOL success = [fileManager fileExistsAtPath:fullpath];
// If the database already exists then return without doing anything
if(success) { NSLog(@"Yes exists"); }else{ NSLog(@"no"); }
//return [documentsDir stringByAppendingPathComponent:appDelegate.filenamefrompath];
NSError* err;
NSLog(@"%@",fullpath);
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:fullpath] error:&err];
//NSString *filePath = [[NSBundle mainBundle] pathForResource:appDelegate.filenamefrompath ofType:@"aif"];
// NSURL * fileURL = [[NSURL alloc] initFileURLWithPath:filePath]; // player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
NSLog(@"%@",appDelegate.filenamefrompath);
player.delegate = self;
if( err ){
//bail!
NSLog(@"Failed with reason: %@", [err localizedDescription]);
}
[player play];
}
请检查我的代码是否有错误
答案 0 :(得分:0)
表面上的代码看起来不错
奇怪地追踪错误定义并非易事
他们在MacErrors.h中
fnfErr = -43, /*File not found*/
您可以验证您在[NSURL fileURLWithPath:fullpath]
中为播放器提供的网址是否有效。
更重要的是你想在Sim文件夹中播放的文件?
如果这应该是IBAction,那么和关闭主题,那么签名应该是
-(IBAction)playevent:(id)sender