开发者

Basic description on how to record video in iOs 4

Hey guys i was curious if anybody开发者_C百科 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜