0

我在 iPad 应用程序中录制视频,它工作正常,但问题是我希望用户可以录制长达 30 秒的视频,但只能以任何方式让用户绑定长达 30 秒,然后显示警报。

-(void)onHomeButtonClickVideo{

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
   {
    NSArray *mediaTypes = [NSArray arrayWithObject:(NSString*)kUTTypeMovie];
    picker.mediaTypes = mediaTypes ;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo ;
[self presentModalViewController:picker animated:NO];
[picker release];
}
   else
    {   
    UIAlertView *alt=[[UIAlertView alloc]initWithTitle:@"Error" message:@" Camera Facility is not available with this Device" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alt show];
    [alt release];
}
}
4

2 回答 2

0

首先将图像选择器对象作为 .h 文件中的属性

像这样的代码

 -(void)onHomeButtonClickVideo{

picker = [[UIImagePickerController alloc] init];
picker.delegate = self;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])

   {
    NSArray *mediaTypes = [NSArray arrayWithObject:(NSString*)kUTTypeMovie];
    picker.mediaTypes = mediaTypes ;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo ;
[self presentModalViewController:picker animated:NO];

[self performSelector:@selector(stopCapturingVideoAfterSomeTime) withObject:nil afterDelay:30];

}

   else
    {


    UIAlertView *alt=[[UIAlertView alloc]initWithTitle:@"Error" message:@" Camera Facility is not available with this Device" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alt show];
    [alt release];


}


-(void)stopCapturingVideoAfterSomeTime
{
   [picker stopVideoCapture];

 // what ever code you want at the time of video stop : show alert or any thing
}
于 2013-06-05T05:58:09.120 回答
0

使用下面的代码

     UIImagePickerController* picker = .......
        picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
        picker.videoMaximumDuration = 30; //in seconds
        record.saveToAlbum = YES;
        [self loadCamScreensWithPicker:picker];

 NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
 NSData *data_Page = [NSData dataWithContentsOfURL:videoURL];
 if (([data_Page length]/1024/1024)<=30) 
    {

       // Not Exceed 30 SEC
    }
    else{

       // Exceed 30 Seconds
    }
于 2013-06-05T06:04:52.433 回答