Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture video and to save into documents directory of iPhone

Tags:

iphone

I want to capture video in iphone4 and at completion I want to store in documents directory of iPhone.Please help .I am able to capture video using UIImagePickerController but not able to save it into documents directory.

like image 764
mobile.jugnu Avatar asked Aug 07 '11 03:08

mobile.jugnu


2 Answers

If you want to save videos with a UIImagePicker, you can easily save them to the Photos Album via:

- (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 to the Photos Album, and keep a reference path to the movie for use later. I'm not quite sure if this is what you need, but it does allow you to save movies.

EDIT: If you really want to save the Movie to documents directory, simply take the above code, and change the line:

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

to

NSData * movieData = [NSData dataWithContentsOfURL:movieURL];

This will give you the data of the movie, and from there, you can write that data to the documents directory. Hope that helps!

like image 98
msgambel Avatar answered Oct 23 '22 03:10

msgambel


try this it worked for me:

On save action:

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

call back method

- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

    if (error != nil) {
        NSLog(@"Error: %@", error);
    }

}
like image 41
Kumaran Avatar answered Oct 23 '22 05:10

Kumaran