我尝试从iPod音乐库导出音频文件。我的目标是使用这个iPod音乐库文件在应用程序文档文件夹中创建一个新文件。只有某些项目无法创建文件。以下是我的代码片段。
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL: url options:nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
AVAssetExportSession *exporter = [[AVAssetExportSession alloc]
initWithAsset: songAsset
presetName: AVAssetExportPresetAppleM4A];
exporter.outputFileType = @"com.apple.m4a-audio";
NSString *songName = [filename stringByAppendingString:@".m4a"];
NSString *musicfilepath = [documentsDirectory stringByAppendingPathComponent:@"musics/"];
[[NSFileManager defaultManager] createDirectoryAtPath:musicfilepath withIntermediateDirectories:YES attributes:nil error:nil];
NSString *exportFile = [musicfilepath stringByAppendingPathComponent:songName];
NSError *error1;
if([[NSFileManager defaultManager] fileExistsAtPath:exportFile])
{
[[NSFileManager defaultManager] removeItemAtPath:exportFile error:&error1];
}
NSURL* exportURL = [[NSURL fileURLWithPath:exportFile] retain];
exporter.outputURL = exportURL;
尝试使用错误处理程序块时,出现以下错误:
[exporter exportAsynchronouslyWithCompletionHandler:^{
int exportStatus = exporter.status;
switch (exportStatus) {
case AVAssetExportSessionStatusFailed: {
NSError *exportError = exporter.error;
NSLog (@"AVAssetExportSessionStatusFailed: %@", exportError);
break;
}
}
}];
AVAssetExportSessionStatusFailed: 错误域=AVFoundationErrorDomain 代码=-11800 "操作无法完成" UserInfo=0x214f20 {NSLocalizedFailureReason=发生未知错误(-12124),NSUnderlyingError=0x218270 "操作无法完成。(OSStatus 错误-12124。)", NSLocalizedDescription=操作无法完成}