unable to play audio file from document?
when ever i try to play audio this error appears
2010-08-27 09:13:40.466 VoiceRecorder[3127:207] Failed with reason: The operation couldn’t be completed. (OSStatus error -43.)
what does it mean
I am physically storing file in Iphone Document folder and 开发者_如何学Ccopying its name in my database
so when ever I play it from database its correctly get file path
and file name from document and database concat perfectly but unable to play
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/Documents/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] Failed with reason: The operation couldn’t be completed. (OSStatus error -43.)
need an urgent reply
here is my code
-(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];
}
Please check my code for error
The code looks OK on the surface
Strangely tracking down the errors definitions is not entirely easy
They are in MacErrors.h
fnfErr = -43, /*File not found*/
Can you verify that the URL you are feeding the player in [NSURL fileURLWithPath:fullpath]
is valid.
And more to the point is the file you are trying to play there in the Sim folder?
and off topic if this is supposed to be an IBAction then the signature should be
-(IBAction)playevent:(id)sender
精彩评论