UIImagePickerController will not record video

I want to record a video with UIImagePickerController . My problem is that the method [imagePickerController startVideoCapture]; always returns 0. I am testing an application with iPhone 4S with iOS 5.1. Can someone please help me with this:

 - (IBAction)playButtonPushed:(id)sender { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIView *videoView = self.videoViewController.view; UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] >init]; imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; imagePickerController.mediaTypes = [[NSArray alloc] initWithObjects: (NSString >*)kUTTypeMovie, nil]; imagePickerController.showsCameraControls = NO; imagePickerController.toolbarHidden = NO; imagePickerController.wantsFullScreenLayout = YES; imagePickerController.allowsEditing = YES; imagePickerController.videoQuality = UIImagePickerControllerQualityTypeMedium; imagePickerController.videoMaximumDuration = 30; [imagePickerController startVideoCapture]; imagePickerController.cameraViewTransform = > CGAffineTransformScale(self.imagePickerViewController.cameraViewTransform, CAMERA_TRANSFORM, CAMERA_TRANSFORM); imagePickerController.delegate = self; [self.imagePickerViewController setCameraOverlayView:videoView]; NSLog(@"%s videoCapture: %d", __PRETTY_FUNCTION__, [imagePickerController > startVideoCapture] ); [self presentModalViewController:imagePickerViewController animated:YES]; } } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSLog(@"didFinishPickingMediaWithInfo"); NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; NSData *videoData = [NSData dataWithContentsOfURL:videoURL]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { NSLog(@"Cancel"); } 
+4
source share
4 answers

If IM is not mistaken, the "startVideoCapture" method is a bool

Taken directly from the documentation for the apple:

startVideoCapture

Starts video capture using the camera specified by the UIImagePickerControllerCameraDevice property. - (BOOL) startVideoCapture Return Value

YES on success or NO on failure. This method can return NO for various reasons, including the following:

 Movie capture is already in progress The device does not support movie capture The device is out of disk space 

Discussion

Use this method in combination with a custom overlay view to initiate software movie capture. You can take more than one movie without leaving the interface, but this requires that you hide the default image selection controls.

Calling this method while capturing a movie is not affected. You must call the stopVideoCapture method and then wait for the associated delegate to receive the imagePickerController: didFinishPickingMediaWithInfo: message before you can capture another movie.

Calling this method when the source type of the image picker is set to a value other than UIImagePickerControllerSourceTypeCamera throws an NSInvalidArgumentException.

If you require additional options or more control over video capture, use the video capture methods within the AV Foundation. See the AV Foundation Fundamentals Reference. Availability

 Available in iOS 4.0 and later. 

Announced in UIImagePickerController.h stopVideoCapture

Stops video capture. - (void) stopVideoCapture Discussion

After calling this method to stop the video capture, the system calls the image selection delegate: imagePickerController: doneFinishPickingMediaWithInfo: method. Availability

 Available in iOS 4.0 and later. 

Announced in UIImagePickerController.h

+2
source

I think you need to call the startVideoCapture method after calling presentModalViewController: animated: and not before.

You will probably also need a slight delay (<1s?) After the UIImagePickerController is presented on the screen and the animation is stopped, then call startVideoCapture, otherwise there are times when it does not start recording.

+1
source

I had exactly the same problem. AndyV has everything right, the recording will not start until the collector appears. I spent a lot of time entering a delay with sleep, but the easiest solution is to start the timer after displaying the collector using

 NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(startRecording) userInfo:nil repeats: NO]; 

Then..

 - (void)startRecording { BOOL result = [picker startVideoCapture]; } 
+1
source

I had the same problem and the Apple documentation did not help. This is because they missed the mention that startVideoCapture () might return false if you did not set the capture mode to .video as follows:

 picker.cameraCaptureMode = .video 

This worked for me, and now I can shoot the video.

+1
source

Source: https://habr.com/ru/post/1412434/


All Articles