Graham Slick
Graham Slick

Reputation: 6870

Trigger iphone video recording after x seconds

In a swift app, I want to start recording a video with the camera, after a 10 seconds wait.

Once the 10 seconds wait is over, this function is called:

func startRecording() {
  // trigger video recording
}

So far, when a user clicked on a "Record video button", it displayed the camera interface, and the user then had to click on the built-in record button:

@IBAction func recordVideo(sender: AnyObject) {
        if (UIImagePickerController.isSourceTypeAvailable(.Camera)) {
            if UIImagePickerController.availableCaptureModesForCameraDevice(.Rear) != nil {
                imagePicker.sourceType = .Camera
                imagePicker.mediaTypes = [kUTTypeMovie as String]
                imagePicker.allowsEditing = false
                imagePicker.delegate = self
                locationManager.startUpdatingLocation()
                print(locationManager.location)
                presentViewController(imagePicker, animated: true, completion: {})
            } else {
                postAlert("Rear camera doesn't exist", message: "Application cannot access the camera.")
            }
        } else {
            postAlert("Camera inaccessible", message: "Application cannot access the camera.")
        }
    }

What I'm trying to do, is trigger automatically the recording, 10 seconds after the "Record video button" was hit.

I couldn't find information on how to "trigger" the recording. Is there a way of doing this ?

Thanks for your help

Upvotes: 3

Views: 462

Answers (1)

Gordon Childs
Gordon Childs

Reputation: 36084

You could add this after presenting the UIImagePickerController:

imagePicker.performSelector(#selector(UIImagePickerController.startVideoCapture), withObject: nil, afterDelay: 10)

Upvotes: 2

Related Questions