當前位置:成語大全網 - 新華字典 - iOS AVAudioPlayer播放音頻時,已經將音頻下載了本地,怎麽還出現下面的錯誤啊

iOS AVAudioPlayer播放音頻時,已經將音頻下載了本地,怎麽還出現下面的錯誤啊

妳試壹下我的代碼,這段代碼可以工作。

NSData *audioData = [NSData dataWithContentsOfURL:someURL];

NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *filePath = [NSString stringWithFormat:@"%@/%@.mp3", docDirPath , fileName];

[audioData writeToFile:filePath atomically:YES];

NSError *error;

NSURL *fileURL = [NSURL fileURLWithPath:filePath];

player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];

if (player == nil) {

NSLog(@"AudioPlayer did not load properly: %@", [error description]);

} else {

[player play];

}