我正在从事一个涉及视频捕捉的项目。我本质上想以编程方式捕获视频,这意味着我不希望任何相机或任何东西弹出;我只想在按下两个按钮之间录制视频。
我定义了图像选择器并在按下按钮时开始视频捕获:
if (UIImagePickerController.isSourceTypeAvailable(.camera)) {
imagePicker.sourceType = .camera
imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.front
imagePicker.allowsEditing = false
imagePicker.delegate = self
}
imagePicker.startVideoCapture()
print("Capture started")
后来,我停止了视频捕捉:
imagePicker.stopVideoCapture()
print("capture over")
我知道这应该调用我的方法:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
print("captured")
}
由于某种原因,我的视频没有开始录制,因为 bool 值 imagepicker.startvideocapture 返回 false。我完全不知道为什么会发生这种情况;有人可以提供一些建议吗?
最佳答案
根据文档,startVideoCapture
在以下某些情况下返回 false
值:
This method may return a value of false for various reasons, among them the following:
Movie capture is already in progress
The device does not support movie capture
The device is out of disk space
首先要检查是否发生上述任何情况。而且您正在设备而不是模拟器上进行测试,对吗?
关于Swift ImagePicker 开始视频捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43023652/