Home > OS >  open recorder with button click
open recorder with button click

Time:12-03

I've button and want to open a video recorder, but my code only opens photo capture any easy solutions ?

    @IBAction func uploadVideoButton(_ sender: UIButton) {
        let vc = UIImagePickerController()
        vc.sourceType = .camera
        vc.allowsEditing = true
        vc.delegate = self
        present(vc, animated: true)
    }

CodePudding user response:

You need to tell the picker what kind of media you want.

vc.sourceType = .camera
vc.mediaTypes = [kUTTypeMovie as String]

Remember to import MobileCoreServices too.

Having just quickly tested this, kUTTypeMovie is deprecated so you should look into UTTypeMovie

CodePudding user response:

Compiler Happy Code:

import UniformTypeIdentifiers

 func openCamera() {
    if UIImagePickerController.isSourceTypeAvailable(.camera) {
        let picker = UIImagePickerController()
        picker.allowsEditing = true
        picker.delegate = self
        picker.sourceType = .camera
        picker.showsCameraControls = true
        picker.mediaTypes = [UTType.movie.identifier]
        present(picker, animated: true)
    }
}
  • Related