gpt4 book ai didi

ios - 将视频保存到相机胶卷时出错? [ swift ]

转载 作者:可可西里 更新时间:2023-11-01 02:10:21 25 4
gpt4 key购买 nike

我有一个功能,我想用它来将视频保存到相机胶卷。出于某种原因,我停止录制后没有任何反应?它不会将其保存到相机胶卷或给出除

以外的任何错误

Error Domain=NSCocoaErrorDomain Code=-1 "(null)"

这是我的代码:

@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


}

最佳答案

您在调用 stopRecording 后访问视频文件的时间过早。如前所述here您应该只尝试在 capture(_:didFinishRecordingToOutputFileAt:fromConnections:error:) 委托(delegate)回调中使用 URL,因为一旦您要求停止录制,录制就需要完成对文件的任何写入.

您需要将您的照片库调用移动到该委托(delegate)方法中:

func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [Any]!, error: Error!) {
// PHPhotoLibrary.shared().performChanges...
}

关于ios - 将视频保存到相机胶卷时出错? [ swift ],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41191689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com