tags:

views:

97

answers:

2

Hey guys i was curious if anybody could give me a very brief description of how to make an app record video in iOs 4. I know how to do all the media and whatnot using the os 3 method of using the UIImagePickerController but I do not know if that is still available in iOs4 and if not, could someone please give me a very brief description on how to do it using the new method? (No code required, but is more than welcome.)

-Thank you!

+2  A: 

It's pretty straightforward.

I just made a view-based app with a single button on the interface to test this. The button's action is - (IBAction)shootButtonPressed;

You have to check if the device supports video recording and then configure the image picker controller to only shoot video. This code will only work on an actual device.

In the main view controller header, I made it conform to two protocols: UIImagePickerControllerDelegate and UINavigationControllerDelegate

Then I implemented the button press method like this;

- (IBAction)shootButtonPressed;
{
    BOOL canShootVideo = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];

    if (canShootVideo) {
        UIImagePickerController *videoRecorder = [[UIImagePickerController alloc] init];
        videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
        videoRecorder.delegate = self;

        NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
        NSArray *videoMediaTypesOnly = [mediaTypes filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(SELF contains %@)", @"movie"]];
        BOOL movieOutputPossible = (videoMediaTypesOnly != nil);

        if (movieOutputPossible) {
            videoRecorder.mediaTypes = videoMediaTypesOnly;

            [self presentModalViewController:videoRecorder animated:YES];           
        }
        [videoRecorder release];
    }
} 

You also have to implement two more methods to handle when a movie's shot & chosen and when the user cancels the video camera picker.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissModalViewControllerAnimated:YES];

    // save the movie or something here, pretty much the same as doing a photo
    NSLog(@"movie captured %@", info);
}  

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    // process the cancellation of movie picker here
    NSLog(@"Capture cancelled");
}

Super easy.

For more details, see the Multimedia Programming Guide --> About Audio and Video --> Using Video --> Recording and Editing Video. It's in the Apple Docs, although a little scattered for my taste.

willc2
Quick question: Is it possible to record the video with a filter applied to it? like record black and white videos?
John Stewart
A: 

Okay thank you very much! That's an excellent answer, but I should of explained how big a beginner I was.. I understand how to write the code but what I am not sure of is where the certain lines and strings go. For example, if my app was called videorecorder what would go in the following classes?

videorecordAppDelegate.h videorecordAppDelegate.m videorecordViewController.h videorecordViewController.m main.m

Ryan
Until you get a lot more experience, use the project templates in Xcode or you will drown in boilerplate code that you don't need to write.
willc2
Also, on StackOverflow, ask follow up questions in the "comments" field, under a particular question. The "answer" text field is for users to vote up or vote down to rank the quality of answers.
willc2