如何将视频从文档目录保存到图库?

时间:2013-07-22 06:40:42

标签: ios photo-gallery

如何将文档目录中的视频保存到iOS中的图库,这里我从服务器下载视频并保存在文档目录中,现在我想将其移动到图库。

2 个答案:

答案 0 :(得分:4)

UISaveVideoAtPathToSavedPhotosAlbum(sourcePath,nil,nil,nil);

您可以将sourcePath作为

传递
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

附加您的路径或文件名以获取sourcePath。

NSString *sourcePath = [documentsDirectory stringByAppendingPathComponent:@"youVideo.mp4"]; 

答案 1 :(得分:4)

首先,您需要获取特定的视频路径或文档目录,如: -

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"youVideo.mp4"]; 
NSURL *movieURL = [NSURL fileURLWithPath:path]; 


 ALAssetsLibrary* library = [[[ALAssetsLibrary alloc] init] autorelease];
[library writeVideoAtPathToSavedPhotosAlbum:movieURL
                            completionBlock:^(NSURL *assetURL, NSError *error){/*notify of completion*/}];