我想在iphone4中捕获视频,并且在完成时我想存储在iPhone的文档目录中。请帮助。我能够使用UIImagePickerController捕获视频,但无法将其保存到文档目录中。
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);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.