How to save video from document directory to gallery? [duplicate]

孤街浪徒 提交于 2020-01-04 06:52:09

问题


How to save video in document directory to gallery in iOS,here i downloaded video from server and saved in document directory and now i want to move it to gallery.


回答1:


UISaveVideoAtPathToSavedPhotosAlbum(sourcePath,nil,nil,nil);

you can pass the sourcePath as

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

append your path or file name to get sourcePath.

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



回答2:


First you need to get particular video Path or Document directory like:-

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*/}];


来源:https://stackoverflow.com/questions/17781375/how-to-save-video-from-document-directory-to-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!