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.
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!
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With