How to capture video and save to iPhone document catalog

I want to capture video in iphone4 and upon completion I want to save it in the iPhone document directory. Please, help. I can capture a video using the UIImagePickerController but cannot save it to the document directory.

+6
source share
2 answers

If you want to save videos using UIImagePicker, you can easily save them to a photo album using:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info; { NSURL * movieURL = [[info valueForKey:UIImagePickerControllerMediaURL] retain];// Get the URL of where the movie is stored. UISaveVideoAtPathToSavedPhotosAlbum([movieURL path], nil, nil, nil); } 

This allows you to save it in the photo album and save the link to the movie for later use. I'm not quite sure that this is what you need, but it allows you to save movies.

EDIT: If you really want to save the "Movie to Documents" directory, just grab the above code and change the line:

 UISaveVideoAtPathToSavedPhotosAlbum([movieURL path], nil, nil, nil); 

to

 NSData * movieData = [NSData dataWithContentsOfURL:movieURL]; 

This will give you the movie data, and from there you can write this data to the document catalog. Hope this helps!

+5
source

try it, it worked for me:

In save mode:

  NSURL* videoURL = [mMediaInfoDictionary objectForKey:UIImagePickerControllerMediaURL]; NSString* videoPath=[videoURL path]; UISaveVideoAtPathToSavedPhotosAlbum(videoPath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil); 

callback method

 - (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; if (error != nil) { NSLog(@"Error: %@", error); } } 
+1
source

Source: https://habr.com/ru/post/894469/


All Articles