我试图导出iPod-Library中的音频文件。我的目标是使用此iPod-Library文件在应用程序“文档”文件夹中创建新文件。它无法仅为某些项目创建文件。以下是我的代码片段。某些文件的AVAsset导出失败
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 =操作无法完成}
设备上的文件是否有足够的空间?也他们已经存在,你试图导出他们也许? –