Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift ImagePicker VideoCapture未完成未调用的PickingMedia_Swift_Cocoa Touch_Avfoundation_Avkit - Fatal编程技术网

Swift ImagePicker VideoCapture未完成未调用的PickingMedia

Swift ImagePicker VideoCapture未完成未调用的PickingMedia,swift,cocoa-touch,avfoundation,avkit,Swift,Cocoa Touch,Avfoundation,Avkit,我正在做一个涉及视频捕获的项目。我基本上想通过编程来捕获视频 我定义了imagepicker并开始视频捕获: if (UIImagePickerController.isSourceTypeAvailable(.camera)) { imagePicker.sourceType = .camera imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.front

我正在做一个涉及视频捕获的项目。我基本上想通过编程来捕获视频

我定义了imagepicker并开始视频捕获:

if (UIImagePickerController.isSourceTypeAvailable(.camera)) {
            imagePicker.sourceType = .camera
            imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.front
            imagePicker.allowsEditing = false
            imagePicker.delegate = self

            //present(imagePicker, animated: true, completion: {})
        }
        imagePicker.startVideoCapture()
        print("Capture started")
imagePicker.stopVideoCapture()
    print("capture over")
后来,我停止了视频捕获:

if (UIImagePickerController.isSourceTypeAvailable(.camera)) {
            imagePicker.sourceType = .camera
            imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.front
            imagePicker.allowsEditing = false
            imagePicker.delegate = self

            //present(imagePicker, animated: true, completion: {})
        }
        imagePicker.startVideoCapture()
        print("Capture started")
imagePicker.stopVideoCapture()
    print("capture over")
我知道这应该调用我的方法:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    print("captured")


    if let pickedvideo:NSURL = (info[UIImagePickerControllerMediaURL] as! NSURL) {
        let selectorToCall = Selector("videoWasSavedSuccessfully.didFinishSavingWithError:context:")
        UISaveVideoAtPathToSavedPhotosAlbum(pickedvideo.relativePath!, self, selectorToCall, nil)

        let videoasset = (AVAsset(url: pickedvideo as URL))
        let playeritem = AVPlayerItem(asset: videoasset)
        let player = AVPlayer(playerItem: playeritem)
        let playerViewController = AVPlayerViewController()
        playerViewController.player = player
        self.present(playerViewController, animated: true) {
            playerViewController.player?.play()
        }
    }
}

但是捕获的内容不会被打印出来,即使我知道我正在开始和停止录制,因为捕获开始和捕获结束都会被打印出来。我不确定为什么没有调用该方法。有什么建议吗?

尝试将mediaTypes设置为kUTTypeMovie。

为什么要使用cocoa标签?您应该检查startVideoCapture的返回值。是否返回true?这与是否调用委托方法有什么关系?我建议添加,因为缺少媒体类型。至少我们应该添加缺少的行并检查。然后这应该是一个注释,而不是答案。但是你还不能发表评论。请不要发表评论作为答案。等到你赢得足够的声誉后再发表评论。