本文介绍了iPhone:录像机API中videoMaximumDuration属性的奇怪问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在录像机API中遇到了videoMaximumDuration属性的奇怪问题.我试图解决这个问题超过一个星期,但无法解决.我在几个论坛上发帖,但还没有帮助.

I am facing a strange issue with videoMaximumDuration property in Video recorder API. I am trying to fix this issue more than a week, but couldn't. I posted in several forums, but no help yet.

我正在使用以下代码从应用程序中启动Camera并开始录制视频.根据我的要求,我应该设置录制视频的持续时间.因此,我使用"videoMaximumDuration"属性来设置录制视频的持续时间.

I am using the following code to launch Camera from my application and start recording the video. As per my requirement, i should set the time duration for recording the video to stop. So, i use "videoMaximumDuration" property to set the time duration for recording the video.

if ([types containsObject:(id)kUTTypeMovie])
{
    appDelegate.pickerController = [[UIImagePickerController alloc] init];
    appDelegate.pickerController.delegate = self;
    appDelegate.pickerController.videoQuality = setVideoQuality;

       appDelegate.pickerController.allowsEditing = NO;
    appDelegate.pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    appDelegate.pickerController.showsCameraControls = YES;
    appDelegate.pickerController.navigationBarHidden = YES;
    appDelegate.pickerController.toolbarHidden = YES;
    appDelegate.pickerController.wantsFullScreenLayout = YES;
    appDelegate.pickerController.cameraViewTransform =
    CGAffineTransformScale(appDelegate.pickerController.cameraViewTransform,
                           CAMERA_TRANSFORM_X,
                           CAMERA_TRANSFORM_Y);
    appDelegate.pickerController.mediaTypes = [NSArray arrayWithObject:(id)kUTTypeMovie];
    appDelegate.pickerController.videoMaximumDuration = maxDuration;
    [self presentModalViewController:appDelegate.pickerController animated:YES];
}

问题出在这里:

如果我将videoQuality设置为UIImagePickerControllerQualityTypeHigh,则持续时间(videoMaximumDuration)会按预期工作,即恰好在其持续自动停止录制视频的持续时间之后.如果我去查看相册中录制的视频以确保确定,那么每次录制的视频都很好.如果像这样将videoQuality更改为UIImagePickerControllerQualityTypeMedium(或)UIImagePickerControllerQualityTypeLow,则视频录制的持续时间(videoMaximumDuration)不能正常工作,即它能够在设置的持续时间内自动停止视频录制,没有问题,但是,如果我去查看相册中已录制的视频以确保确定,它不是按照所花费的时间,而是我可以看到较小的视频比我录制的要多.例如,如果我将videoMaximumDuration设置为30秒,则在录制视频后,如果我去查看相册中录制的视频,它最多只能录制22秒. API本身似乎有问题.当我将视频质量用作UIImagePickerControllerQualityTypeHigh时,不会发生这种情况.

If if i set videoQuality as UIImagePickerControllerQualityTypeHigh, then the time duration(videoMaximumDuration) works as expected, i.e exactly after the time duration it stops recording the video automatically. If i go and see that recorded video in Photo album to make sure that, it is recorded well as per the time.If i change the videoQuality to UIImagePickerControllerQualityTypeMedium (or) UIImagePickerControllerQualityTypeLow like that, then the time duration(videoMaximumDuration) for video recording is not working as expected,i.e. it is able to automatically stop the video recording at the time duration set, no issues, But if i go and see that recorded video in Photo album to make sure, it is NOT as per the time taken, rather i can see the smaller video than what i recorded. For example, if i set the videoMaximumDuration for 30 seconds, after recording the video, if i go and see that recorded video in Photo album, it could able to record= only unto 22 seconds. Seems to be issue with the API itself. This is not happening when i use video quality as UIImagePickerControllerQualityTypeHigh.

我什至尝试使用自定义叠加层视图",并通过设置timer(NStimer)通过以下代码来开始和停止录制视频.但是我仍然看到同样的问题.

I tried even using Custom overlay view and do start and stop recording video through code like below by setting timer(NStimer). But still i see the same issue has observed.

    overlay = [[OverlayView alloc]initWithFrame:CGRectMake(0, 0, 768, 1024)];

if ([types containsObject:(id)kUTTypeMovie])
{
    appDelegate.pickerController = [[UIImagePickerController alloc] init];
    appDelegate.pickerController.delegate = self;
    appDelegate.pickerController.videoQuality = setVideoQuality;

   appDelegate.pickerController.allowsEditing = NO;
    appDelegate.pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    appDelegate.pickerController.showsCameraControls = NO;
    appDelegate.pickerController.navigationBarHidden = YES;
    appDelegate.pickerController.toolbarHidden = YES;
    appDelegate.pickerController.wantsFullScreenLayout = YES;
    appDelegate.mTimerSelectionForVideo = maxDuration; // TIME SET HERE IN VARIABLE
    appDelegate.pickerController.cameraViewTransform =
    CGAffineTransformScale(appDelegate.pickerController.cameraViewTransform,
                           CAMERA_TRANSFORM_X,
                           CAMERA_TRANSFORM_Y);
    appDelegate.pickerController.mediaTypes = [NSArray arrayWithObject:(id)kUTTypeMovie];
    appDelegate.pickerController.videoMaximumDuration = maxDuration;
    [self presentModalViewController:appDelegate.pickerController animated:YES];
    appDelegate.pickerController.cameraOverlayView =overlay;
}

OverlayView.m

OverlayView.m

    -(void)startAction:(id)sender
{
    BOOL bStop = TRUE;

    void (^hideControls)(void);
    hideControls = ^(void) {
        cameraSelectionButton.alpha = 0;
        startButton.enabled = NO;
        lbl.hidden = NO;
    };

    void (^recordMovie)(BOOL finished);
    recordMovie = ^(BOOL finished) {
        stopButton.enabled = YES;
        [appDelegate.pickerController startVideoCapture];
    };

    // Hide controls
    [UIView  animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:hideControls completion:recordMovie];

    if ( appDelegate.mTimerSelectionForVideo==0 )
    {
        bStop = FALSE;
    }
    if ( bStop )
        timer = [NSTimer scheduledTimerWithTimeInterval:(appDelegate.mTimerSelectionForVideo)+1
                                             target:self selector:@selector(stopCamera:) userInfo:nil repeats:NO];
}
- (void)stopCamera:(NSTimer *)theTimer
{
    startButton.enabled = YES;

    if ( timer )
    {
        [timer invalidate];
        timer = nil;
    }
    [appDelegate.pickerController stopVideoCapture];
    [appDelegate.pickerController dismissModalViewControllerAnimated:YES];
}

但是我仍然看到同样的问题.为什么按照videoMaximumDuration设置,其他视频质量设置不起作用?我在iPhone 4.1和iPad 4.3上进行了测试,发现了相同的问题.看起来,API或录像机硬件本身存在问题以支持它.

But still i see the same issue observed. Why does other video quality settings not working as per the videoMaximumDuration set?I tested on iPhone 4.1 and iPad 4.3, the same issue has been observed. Looks like, issue with the API or video recorder hardware itself to support it.

如果您的经历有可能(或),有人可以请我来解决此问题吗?

Could someone please guild me to fix this issue if there is any possibility (or) through your experience?

先谢谢您!

推荐答案

通过在相机视图顶部创建一个叠加视图并处理开始/停止代码来解决此问题.

Fixed it by creating an overlay view on top of the camera view and handle start/stop thru code.

这篇关于iPhone:录像机API中videoMaximumDuration属性的奇怪问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 20:52