0

I'm working on a project which involves video capture. I essentially want to capture video programatically.

I defined the imagepicker and started video capture:

if (UIImagePickerController.isSourceTypeAvailable(.camera)) {
            imagePicker.sourceType = .camera
            imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.front
            imagePicker.allowsEditing = false
            imagePicker.delegate = self

            //present(imagePicker, animated: true, completion: {})
        }
        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")


    if let pickedvideo:NSURL = (info[UIImagePickerControllerMediaURL] as! NSURL) {
        let selectorToCall = Selector("videoWasSavedSuccessfully.didFinishSavingWithError:context:")
        UISaveVideoAtPathToSavedPhotosAlbum(pickedvideo.relativePath!, self, selectorToCall, nil)

        let videoasset = (AVAsset(url: pickedvideo as URL))
        let playeritem = AVPlayerItem(asset: videoasset)
        let player = AVPlayer(playerItem: playeritem)
        let playerViewController = AVPlayerViewController()
        playerViewController.player = player
        self.present(playerViewController, animated: true) {
            playerViewController.player?.play()
        }
    }
}

but the "captured" doesn't get printed, even though I know I'm starting and stopping the recording, as "Capture started" and "Capture over" are printed. I'm not sure why the method isn't being called. Any suggestions?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
newguy222
  • 111
  • 1
  • 11

1 Answers1

-1

Try setting mediaTypes to kUTTypeMovie.

Hiren Patel
  • 190
  • 7
  • What would this have to do with the delegate method being called or not? – rmaddy Mar 25 '17 at 16:46
  • I suggested to add as it was missing media types. At least we should add missing line and check. – Hiren Patel Mar 25 '17 at 16:53
  • Then this should be a comment, not an answer. But you can't post comments yet. Please don't post comments as answers. Wait until you earn enough reputation to post comments. – rmaddy Mar 25 '17 at 16:55