从 iPhone 应用程序录制视频时设置最长录制时间

3
在我的iPhone应用程序中,用户可以录制视频。我想设置最长录制时间为30秒。有什么想法吗?
使用以下代码:
-(BOOL)startCameraControllerFromViewController:(UIViewController*)controller
                             usingDelegate:(id )delegate {
   if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO)
    || (delegate == nil)
    || (controller == nil)) {
    return NO;
   }
   UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
  cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
 cameraUI.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];

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

[controller presentModalViewController: cameraUI animated: YES];
return YES;
 }

-(void)imagePickerController:(UIImagePickerController *)picker  didFinishPickingMediaWithInfo:(NSDictionary *)info {
 NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:NO];
  if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
    NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
    NSLog(@"movie path %@",moviePath);


    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath)) {
        UISaveVideoAtPathToSavedPhotosAlbum(moviePath, self,
                                              @selector(video:didFinishSavingWithError:contextInfo:), nil);
    }
  }
}

-(void)video:(NSString*)videoPath didFinishSavingWithError:(NSError*)error contextInfo:  (void*)contextInfo {
   if (error) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Video   Saving Failed"
                                                   delegate:nil cancelButtonTitle:@"OK"   otherButtonTitles:nil];
    [alert show];
  } else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Video Saved"   message:@"Saved To Photo Album"
                                                   delegate:self cancelButtonTitle:@"OK"   otherButtonTitles:nil];
    [alert show];
   }
  }
1个回答

4

在配置UIImagePickerController进行视频录制后,您需要设置videoMaxiumDuration属性。

该值是以秒为单位指定的NSTimeInterval,因此如果您想要5分钟的视频,则需要将其设置为300秒。


你是否熟悉这个问题 - http://stackoverflow.com/questions/14455583/how-to-set-video-recording-time-as-countdown-in-uiimagepicker? - Nithin M Keloth

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接