我试图从 iPod 库中导出音频文件。我的目标是使用此 iPod-Library 文件在 app Document 文件夹中创建新文件。它无法仅为某些项目创建文件。下面是我的代码片段。
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: Error Domain=AVFoundationErrorDomain Code=-11800“操作无法完成” UserInfo=0x214f20 {NSLocalizedFailureReason=发生未知错误(-12124),NSUnderlyingError=0x218270“操作无法完成。(OSStatus错误-12124 .)", NSLocalizedDescription=操作无法完成}