Ios 将视频保存到摄影机卷时出错?[快速]
我有一个功能,我想用它将视频保存到摄像机的镜头上。出于某种原因,在我停止录音后,什么都没有发生?它不会将其保存到相机卷,也不会给出除Ios 将视频保存到摄影机卷时出错?[快速],ios,swift,photo-gallery,Ios,Swift,Photo Gallery,我有一个功能,我想用它将视频保存到摄像机的镜头上。出于某种原因,在我停止录音后,什么都没有发生?它不会将其保存到相机卷,也不会给出除 Error Domain=NSCocoaErrorDomain code=-1“(空)” 这是我的密码: @IBAction func record(_ sender: UIButton) { if recordingInProgress{ output.stopRecording() recordingLabel.tex
Error Domain=NSCocoaErrorDomain code=-1“(空)”
这是我的密码:
@IBAction func record(_ sender: UIButton) {
if recordingInProgress{
output.stopRecording()
recordingLabel.textColor = UIColor.rgb(red: 173, green: 173, blue: 173)
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: self.outputURL as URL)
}) { saved, error in
if saved {
let alertController = UIAlertController(title: "Your video was successfully saved", message: nil, preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}
}
}
else{
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString
let outputPath = "\(documentsPath)/output.mov"
outputURL = NSURL(fileURLWithPath: outputPath)
output.startRecording(toOutputFileURL: outputURL as URL!, recordingDelegate: self)
recordingLabel.textColor = UIColor.rgb(red: 250, green: 3, blue: 33)
}
recordingInProgress = !recordingInProgress
}
您在调用
停止录制
后访问视频文件的时间过快。如上所述,您应该只尝试使用捕获(\uUU9:didFinishRecordingToOutputFileAt:fromConnections:error:)
委托回调中的URL,因为一旦您要求停止录制,需要完成对文件的任何写入
您将希望将照片库调用移动到该委托方法中:
func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [Any]!, error: Error!) {
// PHPhotoLibrary.shared().performChanges...
}