[英]open recorder with button click
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)
}
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.记得也要导入 MobileCoreServices。
Having just quickly tested this, kUTTypeMovie is deprecated so you should look into UTTypeMovie刚刚对此进行了快速测试,不推荐使用 kUTTypeMovie,因此您应该查看 UTTypeMovie
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)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.