Swift ImagePicker 开始视频捕获

标签 swift video avfoundation avkit

我正在从事一个涉及视频捕捉的项目。我本质上想以编程方式捕获视频,这意味着我不希望任何相机或任何东西弹出;我只想在按下两个按钮之间录制视频。

我定义了图像选择器并在按下按钮时开始视频捕获:

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/

相关文章:

ios - 采访 Que Tableview reuseIdentifier 内部工作

swift - 使用 Swift2 从 AppDelegate 重新打开 iOS 应用程序到指定的导航 Controller

iphone - MPMoviePlayerController "Loading Movie..."

c# - 从 vimeo 下载视频

security - 使用动态水印保护流媒体视频

ios - 尝试在 iOS 中使用 AVAssetDownloadURLSession 下载 m3u8 视频时出错

ios - 以 Swifty(/协议(protocol))方式在 Controller 之间传递信息?

swift - 简化 UIView 动画 if/else

ios - 使用 AVFoundation 录制视频会停止声音

ios - 如何提高AVAudioEngine.installTap()的回调频率