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

1 に答える 1

4

ビデオ録画用に構成した後、UIImagePickerControllerでvideoMaxiumDurationプロパティを設定する必要があります。

値は秒単位で指定されるNSTimeIntervalであるため、5分のビデオが必要な場合は300秒に設定する必要があります。

于 2013-01-22T09:27:02.043 に答える