2010-09-03 126 views
3

任何人都可以在錄製後提供任何示例代碼以保存視頻。 我可以使用UIImagePickerController錄製視頻。保存錄制的視頻

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]; 
    } 

但如何保存它。任何人都可以告訴。

在此先感謝

回答

0
- (void)saveVideo:(NSURL *)videoUrl { 
    NSData *videoData = [NSData dataWithContentsOfURL:videoUrl]; 
    [videoData writeToFile:@"YOUR_PATH_HERE" atomically:YES]; 
}  

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    NSString *type = [mediaDict objectForKey:UIImagePickerControllerMediaType]; 

    if ([type isEqualToString:(NSString *)kUTTypeVideo] || 
     [type isEqualToString:(NSString *)kUTTypeMovie]) { // movie != video 
     NSURL *videoURL [mediaDict objectForKey:UIImagePickerControllerMediaURL]; 
     [self saveVideo:videoUrl]; 
    } 

} 

這是情況下,你要保存的視頻轉換,你可以控制一些文件的路徑。您也可以保存爲「已保存的照片」

+0

可以指出您應該將MobileCoreServices添加到項目並導入以使用上述解決方案:) – bennythemink 2012-07-17 04:11:21