Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save a Video that I record in my app

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:-)

like image 420
jwknz Avatar asked Nov 29 '11 00:11

jwknz


People also ask

How can I save my mobile recordings?

Some Android™ devices, like the Samsung Galaxy S20+ 5G, come with a voice recording app pre-installed. Hit the red record button when you want to start the recording, and then once again to stop it. From here, you can hit the button again to continue recording, or save the file to your recording archive.

Where is my record app on my phone?

Open the App Drawer by swiping up from the bottom of your screen. 2. If you don't immediately see the Voice Recorder app, you may need to open a folder that will likely have the phone's name as its label (Samsung, e.g.). Do so, then tap the Voice Recorder app.


1 Answers

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];
}
like image 108
SimplyKiwi Avatar answered Oct 21 '22 00:10

SimplyKiwi