How to save video from document directory to galle

2019-07-14 19:14发布

This question already has an answer here:

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.

2条回答
ら.Afraid
2楼-- · 2019-07-14 19:17

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*/}];
查看更多
叼着烟拽天下
3楼-- · 2019-07-14 19:22
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"]; 
查看更多
登录 后发表回答