Save a Video that I record in my app
10,803
Try this:
UISaveVideoAtPathToSavedPhotosAlbum(moviepath,nil,nil,nil);
Edit: Try this and modify your code to this method:
// For responding to the user tapping Cancel.
- (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker {
[[picker parentViewController] dismissModalViewControllerAnimated: YES];
[picker release];
}
// For responding to the user accepting a newly-captured picture or movie
- (void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
UIImage *originalImage, *editedImage, *imageToSave;
// Handle a still image capture
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0)
== kCFCompareEqualTo) {
editedImage = (UIImage *) [info objectForKey:
UIImagePickerControllerEditedImage];
originalImage = (UIImage *) [info objectForKey:
UIImagePickerControllerOriginalImage];
if (editedImage) {
imageToSave = editedImage;
} else {
imageToSave = originalImage;
}
// Save the new image (original or edited) to the Camera Roll
UIImageWriteToSavedPhotosAlbum (imageToSave, nil, nil , nil);
}
// Handle a movie capture
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo) {
NSString *moviePath = [[info objectForKey:
UIImagePickerControllerMediaURL] path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (
moviePath, nil, nil, nil);
}
}
[[picker parentViewController] dismissModalViewControllerAnimated: YES];
[picker release];
}
Author by
jwknz
Hi, Working as a CS Tutor and enjoying full stack development in my day-to-day coding. Cheers, Jeff
Updated on July 30, 2022Comments
-
jwknz over 1 year
I am succeeding in understanding how to make a camera app in my learning journey:-)
The only thing I am stuck with is saving a video that I have recorded. I am able to save a photo, but the same does not work for videos.
So I think I have almost got it with the help of iBrad Apps.
got this code:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; [self dismissModalViewControllerAnimated:YES]; if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) { UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; imageView.image = image; if (newMedia) UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:finishedSavingWithError:contextInfo:), nil); } else{ if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) { UIImage *movie = [info objectForKey:UIImagePickerControllerQualityTypeHigh]; videoRecorder2.image = movie; if (newMedia) UISaveVideoAtPathToSavedPhotosAlbum(movie, self, @selector(movie:finishedSavingWithError:contextInfo:), nil); }}}
I have an if statement because the app can take both video and still images.
The first part is for still - which works and then the second part I am still tutu-ing with:-)
-
jwknz over 12 yearsSounds like I the right way - I have added some code to show what I am doing - cheers
-
SimplyKiwi over 12 yearsCheck if movie is nil or if newMedia is nil.
-
jwknz over 12 yearsSorry is that a question or the answer? newMedia is a Boolean and so I am thinking that it should be nil - so that it can save the clip right? maybe I am on the wrong trail here.
-
SimplyKiwi over 12 yearsCheck that both of those objects exist then I we will work from there.
-
jwknz over 12 yearsIBOutlet UIImageView *videoRecorder2; BOOL newMedia; There they are in my .h file - they come up the green-ish color so it is recognizing them.
-
SimplyKiwi over 12 yearsuse an NSLog and check if they exist.
-
jwknz over 12 yearsok - mmmm maybe bad code practice, but I have never used NSLog before. sorry:-(
-
SimplyKiwi over 12 yearstry removing this line: videoRecorder2.image = movie;
-
jwknz over 12 yearsI am getting this warning: Incompatible pointer types passing 'UIImage *' to parameter of type 'NSString *'
-
jwknz over 12 yearsok cool :-) It seems to work, I still got a few bugs, but i'll learn and work through them - thanks iBrad:-)
-
SimplyKiwi over 12 yearsno problem! Yea your main issue before was that you were setting a Image to a Video. haha :)
-
jwknz over 12 yearsok - yeah that makes sense, when I tried your code it would not dismiss the view though, neither images or video - so I combined my initial code and after the else entered your video part of the solution and it works after that. I'll do some more staring at the screen and see if I can make it work cleaner:-)
-
Lior Frenkel over 12 yearsThanks! How can I later load up this video from the saved place to the GUI?
-
SimplyKiwi almost 12 yearsSorry for the really late response. Just use MPMoviePlayerController and do it that way since it is the easiest way. :P