2010-08-30 71 views
0

當我嘗試播放音頻時出現此錯誤無法播放文件中的音頻文件?

2010-08-27 09:13:40.466 VoiceRecorder [3127:207]失敗,原因:操作無法完成。 (OSStatus錯誤-43)。

這是什麼意思

我身體儲存文件在iPhone文檔文件夾,並在我的數據庫複製其名稱

所以當我曾經從數據庫中玩它得到正確文件路徑

從文件和數據庫CONCAT完美,但無法

和文件名玩

2010-08-30 12:22:00.592 VoiceRecorder [8140:207] /用戶/用戶名/庫/ Application Support/iPhone模擬器/ 4.0.1 /鴨錄音機/ 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]失敗,原因:操作無法完成。 (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:文件路徑]。 // 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

的代碼看起來OK表面上

奇怪的是跟蹤誤差的定義不完全是容易

他們在MacErrors.h

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

您能否驗證您在[NSURL fileURLWithPath:fullpath]中給玩家發送的URL是否有效。

更重要的是你正試圖在Sim文件夾中播放的文件?

和題外話,如果這應該是一個IBAction爲隨後的簽名應該是
-(IBAction)playevent:(id)sender

+0

肯定的NSLog(@ 「%@」,FULLPATH);給我這個結果 /用戶/用戶/庫/應用程序支持/ iPhone模擬器/ 4.0.1 /應用程序/ 4911A7B9-E121-43FF-8C4A-BABC73BD523B/Documents/30Aug10_01_25_29.aif – 2010-08-30 09:24:51

+0

是的我已跟蹤它所在的文件IPHONE SIMULATOR文檔文件夾 – 2010-08-30 09:26:26