我在Video recorder API中遇到了videoMaximumDuration属性的奇怪问题。我试图解决这个问题超过一个星期,但不能。我发布了几个论坛,但还没有帮助。
我使用以下代码从我的应用程序启动Camera并开始录制视频。根据我的要求,我应该设置录制视频的持续时间。因此,我使用“videoMaximumDuration”属性来设置录制视频的持续时间。
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时,这种情况不会发生。
我甚至尝试使用自定义叠加视图,并通过设置计时器(NStimer)来启动和停止通过以下代码录制视频。但我仍然看到同样的问题已经发现。
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
-(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或录像机硬件本身支持它。
如果有可能(或)根据您的经验,有人可以帮我解决这个问题吗?
提前谢谢你!
答案 0 :(得分:1)
通过在摄像机视图顶部创建叠加视图并通过代码处理开始/停止来修复它。