0

I'm working on a project which involves video capture. I essentially want to capture video programatically, meaning that I don't want any camera or anything to pop up; I just want video to be recorded between the times two buttons are pressed.

I defined the imagepicker and started video capture when a button is pressed:

if (UIImagePickerController.isSourceTypeAvailable(.camera)) {
        imagePicker.sourceType = .camera
        imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.front
        imagePicker.allowsEditing = false
        imagePicker.delegate = self
    }
    imagePicker.startVideoCapture()
    print("Capture started")

later, I stopped video capture:

imagePicker.stopVideoCapture()
print("capture over")

I know this should be calling my method:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    print("captured")
}

For some reason my video doesn't start recording, as the boolean imagepicker.startvideocapture returns false. I'm completely stuck on why this is happening; could someone please provide some suggestions?

newguy222
  • 111
  • 1
  • 11
  • Don't you need to present the image picker before trying to capture video? – rmaddy Mar 26 '17 at 01:07
  • And why do you try to call `startVideoCapture` outside of the `if` block? – rmaddy Mar 26 '17 at 01:08
  • And where do you actually create the picker? You should only create it and use it if the source type is available. – rmaddy Mar 26 '17 at 01:09
  • I thought I only needed to use the start and stopvideocapture methods; I'm trying to record without presenting any camera. And I created the picker at the beginning of the class. – newguy222 Mar 26 '17 at 01:50

2 Answers2

0

According to the documentation, startVideoCapture returns a false value under some of these circumstances:

This method may return a value of false for various reasons, among them the following:

Movie capture is already in progress

The device does not support movie capture

The device is out of disk space

The first thing to check would be if any of the above is happening. And you are testing on device instead of the simulator, right?

Community
  • 1
  • 1
Fahim
  • 3,466
  • 1
  • 12
  • 18
  • yes, I am, But I'm pretty sure none of these apply; the device supports media capture, its not out of disk space, and I know I'm not already capturing movie. – newguy222 Mar 26 '17 at 01:49
  • Essentially, `UIImagePickerController` is meant for instances where you do want a UI. If you don't want any UI, you might want to look at `AVFoundation` to do the video recording. So what you are trying to do here might not work because you are trying not to show any UI. – Fahim Mar 26 '17 at 01:53
0

Try this..

imagePicker.CameraCaptureMode = .video

because CameraCaptureMode // default is Photo, not video

or

May be you're not informing the UIImagePickerController to record video. So try this line

imagePicker.mediaTypes = [kUTTypeMovie as String]
Swetha Lakshmi
  • 259
  • 5
  • 12