如何使用iphone相机拍摄视频

时间:2012-05-16 12:37:40

标签: iphone

我正在开发一个应用程序。我需要使用相机拍摄视频。所以请告诉我如何做这个。

3 个答案:

答案 0 :(得分:1)

仔细阅读UIImagePickerController Class Reference。它将告诉您如何解决您的问题。

答案 1 :(得分:0)

我假设您知道如何使用UIImagePickerController

#import <MediaPlayer/MediaPlayer.h> // add MediaPlayer.framework

- (IBAction) startCamera
{
    UIImagePickerController * startCamera;
    startCamera = [[UIImagePickerController alloc] init];
    startCamera.delegate = self;

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
    {           
        NSArray *mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
        startCamera.mediaTypes = mediaTypes ;
        startCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
        startCamera.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo ;
        startCamera.allowsEditing = YES ;

    } 
    else
    {
        startCamera.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    }

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

答案 2 :(得分:0)

试试这段代码。仅在设备中测试此代码。在UIImagePickerDelegate方法中处理录制的视频。

UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
picker.delegate = self; 
picker.allowsEditing = YES;
if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])) 
{
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentModalViewController: picker animated:YES]; 
}
else
{
    NSLog(@"Put alert no camer found");
        // Put alert no camer found
}
[picker release];