Save video in video app?

Can I take the video embedded in the application and save it in the camera frame? If so, how? Is this the same property of UIWriteImage?

+3
source share
2 answers

You can try this code, assuming you already know how to save the image:

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
       //Save the video
       NSURL *movieUrl = [info objectForKey:UIImagePickerControllerMediaURL];
       UISaveVideoAtPathToSavedPhotosAlbum([movieUrl relativePath], self,@selector(movie:didFinishSavingWithError:contextInfo:), nil);
    }
}

Or you could try:

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  if([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
    NSURL *movieUrl = [info objectForKey:UIImagePickerControllerMediaURL];
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library writeVideoAtPathToSavedPhotosAlbum:movieUrl completionBlock:^(NSURL *assetURL, NSError *error){
        if(error) {
            NSLog(@"CameraViewController: Error on saving movie : %@ {imagePickerController}", error);
        }
        else {
            NSLog(@"URL: %@", assetURL);
        }
    }];
  }
}
+11
source

For iOS 8 and above, use PHPhotoLibrary . ALAssetsLibrary is deprecated.

Include:

@import PhotosUI;

And then use this to save your movie:

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
 {
     [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:<%Your Movie URL%>];
 }
                                  completionHandler:^(BOOL success, NSError *error)
 {
     if (success) {
         NSLog(@"Movie saved to camera roll.");
     }
     else {
         NSLog(@"Could not save movie to camera roll. Error: %@", error);
     }
 }];
+2
source

All Articles