我正在开展一个涉及视频捕捉的项目。我本质上想以编程方式捕获视频。
我定义了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")
我知道这应该是我的方法:
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()
}
}
}
但是“捕获”不会被打印,即使我知道我正在开始并停止录制,因为“Capture started”和“Capture over”都会打印出来。我不确定为什么没有调用该方法。有什么建议吗?
答案 0 :(得分:-1)
尝试将mediaTypes设置为kUTTypeMovie。