我想在ios设备上导出带有objective-c的.mov
文件,这是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
//NSURL *videoUrl = [[NSBundle mainBundle] URLForResource:@"4a213c6f-d038-494c-bed2-07ed50aef5ac" withExtension:@"mov"];
NSURL *videoUrl = [NSURL URLWithString:@"http://gamecdn.gifmiao.com/wallpaper/4a213c6f-d038-494c-bed2-07ed50aef5ac.mov"];
AVURLAsset *assets = [[AVURLAsset alloc] initWithURL:videoUrl options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:assets presetName:AVAssetExportPresetPassthrough];
NSURL *exportUrl = [[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject] URLByAppendingPathComponent:@"export.mov"];
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
exportSession.outputURL = exportUrl;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
if(exportSession.status == AVAssetExportSessionStatusCompleted){
NSLog(@"export successfully at :%@", exportUrl);
}else if(exportSession.status == AVAssetExportSessionStatusFailed){
NSLog(@"export failed error is %@", [exportSession.error description]);
}
}];
// Do any additional setup after loading the view, typically from a nib.
}
问题在于,当我使用URL作为http链接构建AVURLAsset
时,导出将失败并显示错误:
Error Domain=AVFoundationErrorDomain Code=-11838 "Operation Stopped" UserInfo={NSLocalizedFailureReason=The operation is not supported for this media., NSLocalizedDescription=Operation Stopped, NSUnderlyingError=0x60400024b820 {Error Domain=NSOSStatusErrorDomain Code=-12109 "(null)"}}
也出现了这个错误:
Task <0F298017-8D66-4ADB-8D65-5656FD256DA4>.<2> finished with error - code: -999
但是当我下载视频文件并将其放入主包的资源(只是拖放到Xcode项目中)时,一切都会正常工作。
为什么会这样,以及如何解决这个问题?