我不知道如何从url下载视频并将其保存到库中。
BOOL compatible = UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([videoURL path]);
// save
NSLog(@"BOOL compatible....%hhd",compatible);
if (compatible){
UISaveVideoAtPathToSavedPhotosAlbum([videoURL path], nil, nil, nil);
NSLog(@"SAVED!!!! %@",[videoURL path]);
}else
{
NSLog(@"INCOMPATIBLE...");
}
下载显示错误的视频时:https://api.quickblox.com/blobs/4185382/download无法保存到保存的照片集: Error Domain=NSURLErrorDomain Code=-1100“在此服务器上找不到请求的Domain=NSURLErrorDomain。UserInfo=0x7f9c13ccb130 {NSUnderlyingError=0x7f9c13cc3aa0“操作无法完成。没有这样的文件或目录”,
发布于 2016-04-19 22:56:24
使用这个代码,我希望它能正常工作:
-(void)DownloadVideo
{
//download the file in a seperate thread.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Downloading Started");
NSString *urlToDownload = @"http://www.somewhere.com/thefile.mp4";
NSURL *url = [NSURL URLWithString:urlToDownload];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"thefile.mp4"];
//saving is done on main thread
dispatch_async(dispatch_get_main_queue(), ^{
[urlData writeToFile:filePath atomically:YES];
NSLog(@"File Saved !");
});
}
});
}
发布于 2016-04-19 22:50:31
在苹果的文档中,我认为UIVideoAtPathIsCompatibleWithSavedPhotosAlbum
只工作于本地文件,而不是远程文件。UISaveVideoAtPathToSavedPhotosAlbum
也是如此。
您需要先将文件下载到设备上,然后才能使用UIVideoAtPathIsCompatibleWithSavedPhotosAlbum
。我建议使用像AFNetworking这样的工具来实现这个目标。
https://stackoverflow.com/questions/36735640
复制相似问题