这是我开始录制会话的代码。
var recordingDelegate:AVCaptureFileOutputRecordingDelegate? = self
cameraSession.beginConfiguration()
self.cameraSession.addOutput(videoFileOutput)
cameraSession.commitConfiguration()
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
filePath = documentsURL.appendingPathComponent("temp.mp4")
videoFileOutput.startRecording(toOutputFileURL: filePath, recordingDelegate: recordingDelegate)
这是之后录制视频的代码。
self.videoFileOutput.stopRecording()
UISaveVideoAtPathToSavedPhotosAlbum((filePath?.relativePath)!, nil, nil, nil)
cameraSession.beginConfiguration()
cameraSession.removeOutput(videoFileOutput)
cameraSession.commitConfiguration()
这在 xcode 9 出现之前就可以使用,但是现在当我尝试停止我的视频时,它会导致我的应用程序崩溃,并且 xcode 会抛出错误 Thread 8 signal SIGABART 0_abort_with_payload。我的代码与本节的 xcode 8 相比没有变化,但现在它崩溃了。除了此错误代码之外,我找不到此崩溃的原因。我怀疑这与我保存视频的方式有关。我曾尝试更改 appendingPathComponent,但没有任何区别。