首页 文章

无法播放文件中的音频文件?

提问于
浏览
0

当我尝试播放音频时,会出现此错误

2010-08-27 09:13:40.466 VoiceRecorder [1]原因失败:操作无法完成。 (OSStatus 错误-43.)

这是什么意思

我正在将文件存储在 Iphone Document 文件夹中,并在我的数据库中复制其名称

所以,当我从数据库中播放它时,它正确获取文件路径

和文件和数据库中的文件名完美地连接但无法播放

2010-08-30 12:22:00.592 VoiceRecorder [2] /Users/Username/Library/Application Support/iPhone Simulator/4.0.1/Applications/4BF0B5C7-59C9-462F-94EC- 662EBCE8505E/Documents/30Aug10_12_21_58.aif 2010-08-30 12:22:00.593 VoiceRecorder [3] 30Aug10-43.)21_58.aif 2010-08-30 12:22:00.618 VoiceRecorder [4]原因失败:操作无法完成。 (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 = [[7] initFileURLWithPath:filePath]; // player = [[8] initWithContentsOfURL:fileURL error:nil];

NSLog(@"%@",appDelegate.filenamefrompath);
player.delegate = self;

if( err ){
    //bail!
    NSLog(@"Failed with reason: %@", [err localizedDescription]);
}

[player play];

}

请检查我的代码是否有错误

1 回答

  • 0

    表面上的代码看起来不错

    奇怪地追踪错误定义并不容易

    他们在 MacErrors.h

    fnfErr = -43, /*File not found*/

    您能否验证在[NSURL fileURLWithPath:fullpath]中为播放器提供的 URL 是否有效。

    更重要的是你试图在 Sim 文件夹中播放的文件?

    如果这应该是一个 IBAction,那么签名就应该是
    -(IBAction)playevent:(id)sender

相关问题