简体   繁体   中英

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

你可以在呈现UIImagePickerController之后添加它:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM