捕获视频并在iphone中的MFMailComposer中发送此视频

时间:2011-06-01 15:07:45

标签: objective-c ios4

在我的应用中,我已经为捕获视频编写了此代码

  -(IBAction)takeVideo:(id)sender {

        [self startCameraControllerFromViewController: self

                                        usingDelegate: self]; 
}

    - (BOOL) startCameraControllerFromViewController: (UIViewController*) controller usingDelegate: (id <UIImagePickerControllerDelegate, UINavigationControllerDelegate>) delegate {

        if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO) || (delegate == nil) || (controller == nil))

            return NO;

        cameraUI = [[UIImagePickerController alloc] init];

        cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;

        // Displays a control that allows the user to choose picture or

        // movie capture, if both are available:

        cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];

        // Hides the controls for moving & scaling pictures, or for

        // trimming movies. To instead show the controls, use YES.

        cameraUI.allowsEditing = NO;
        cameraUI.delegate = delegate;

        [controller presentModalViewController: cameraUI animated: YES];

        return YES;      }


    - (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker {

        [[picker parentViewController] dismissModalViewControllerAnimated: YES];

        [picker release];   
 }

    - (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {


        // Handle a movie capture       cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];    NSString
    *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
        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];   
 }

编译并运行此代码,其工作和 拍摄视频后我按下使用按钮保存视频然后应用程序崩溃并在终端上显示“EXC_BAD_ACCESS”错误消息

所以,请帮我解决这个错误

1 个答案:

答案 0 :(得分:1)

在iOS 4或更高版本中,您可以使用UIImagePickerController的实例来捕获视频。这是一个相当高级的便利类,因此您可以控制捕获然后操纵捕获的视频的程度是有限的。您可能不得不使用AV Foundation中提供的较低级别的API。

获得视频数据后,您应该能够将其作为mime附件附加到您撰写的电子邮件中。您只需要NSData对象中的视频,并且必须指定附件的MIME类型。