Save Video to Photo Library - iPhone SDK

Is there a way to save the video in the Documents folder in the Photo Library? I have a video link in the document catalog, I just don’t know how to save it in the Photos application.

Thanks,

Kevin

+4
source share
3 answers

If you first save it to a local directory, you can save it as.

ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init]; [assetLibrary writeVideoAtPathToSavedPhotosAlbum:url completionBlock:^(NSURL *assetURL, NSError *error){ if(error) { NSLog(@"error while saving to camera roll %@",[error localizedDescription]); } else { //For removing the back up copy from the documents directory NSError *removeError = nil; [[NSFileManager defaultManager] removeItemAtURL:url error:&removeError]; NSLog(@"%@",[removeError localizedDescription]); } }]; 
+6
source

try it

You can also use this code to download and save videos from the Internet to Photos.

 NSURL *videoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"Your Video Url or Path"]]; dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); dispatch_async(q, ^{ NSData *videoData = [NSData dataWithContentsOfURL:videoUrl]; dispatch_async(dispatch_get_main_queue(), ^{ // Write it to cache directory NSString *videoPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"file.mov"]; [videoData writeToFile:videoPath atomically:YES]; // After that use this path to save it to PhotoLibrary ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:videoPath] completionBlock:^(NSURL *assetURL, NSError *error) { if (error) { NSLog("Error"); } else { NSLog("Success"); } }]; }); }); 
0
source

All Articles