2010-04-12 129 views
1

我使用下面的代碼來記錄視頻。在iPhone中捕獲視頻

UIImagePickerController *m_objpicker;=[[UIImagePickerController alloc] init]; 
    m_objpicker.sourceType = UIImagePickerControllerSourceTypeCamera;   

    m_objpicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie]; 

    // hide the camera controls 
    //picker.showsCameraControls=NO; 
    m_objpicker.delegate = self; 
    //picker.allowsImageEditing = NO; 
    m_objpicker.allowsEditing=NO; 
    // and put our overlay view in 
    //picker.cameraOverlayView=m_objOverlayView; 
    [self presentModalViewController:m_objpicker animated:YES]; 

當我們完成錄音

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

    NSURL *m_objMediaURL=[info objectForKey:UIImagePickerControllerMediaURL]; 

    [m_objpicker dismissModalViewControllerAnimated:YES]; 

} 

我的疑問是,如何將捕獲的視頻保存到我們指定的位置。還有如何使用 UISaveVideoAtPathToSavedPhotosAlbum。

什麼所有的事情,我需要在我的代碼修改,這樣我可以保存視頻到指定位置

感謝,

回答

1

如果你想保存在相機膠捲照片/視頻專輯電話:

定義:

void UISaveVideoAtPathToSavedPhotosAlbum (
    NSString *videoPath, 
    id completionTarget, 
    SEL completionSelector, 
    void *contextInfo 
); 

在哪裏以及如何執行它:

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

{ 

.... code here ..... 

NSString* m_objMediaURL= [info objectForKey:UIImagePickerControllerMediaURL]; 

//remember to test that the video is compatible for saving to the photos album 

UISaveVideoAtPathToSavedPhotosAlbum(m_objMediaURL, self, @selector(video:didFinishSavingWithError:contextInfo:), nil); 

.... code here ..... 

} 

除了保存到我不推薦的應用程序包之外,除了將其保存到相機卷re:位置之外,沒有任何控制權。

+0

請將此作爲正確回答:這個地方是給和拿。 – Lance 2010-07-28 21:57:31

0

要保存的視頻在相冊:

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

NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; 

      if (_newMedia){ 
         if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(tempFilePath)) 
           { 
           // Copy it to the camera roll. 
           UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, @selector(video:didFinishSavingWithError:contextInfo:), (__bridge void *)(tempFilePath)); 
           } 
         } 


-(void) video: (NSString *) videoPath 
didFinishSavingWithError: (NSError *) error 
    contextInfo: (void *) contextInfo { 


NSLog(@"Finished saving video with error: %@", error); 

}