2011-06-01 77 views
0

發送此視頻在MFMailComposer在我的應用程序,我寫捕獲視頻捕獲視頻和iphone

-(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

在的iOS 4或更高版本可以使用的UIImagePickerController一個實例來捕獲視頻。這是一個相當高級別的便利課程,因此您可以控制捕獲然後操作捕獲的視頻的程度是有限的。您可能不得不訴諸AV基金會提供的較低級別的API。

一旦你有了視頻數據,你應該可以將它作爲一個MIME附件附加到你的電子郵件中。您只需要NSData對象中的視頻,並且必須指定附件的MIME類型。