除非我有以下几行,否则似乎我的回调不会运行:
let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
view.layer.addSublayer(previewLayer)
previewLayer.frame = view.frame
即使回调似乎响应:
let dataOutput = AVCaptureVideoDataOutput()
dataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue"))
captureSession.addOutput(dataOutput)
这是回调函数的声明:
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection)
弄清楚了; 您需要两个DispatchQueue,一个用于配置和启动CaptureSession
,另一个在其中CaptureSession
运行。
sessionQueue.async { [unowned self] in
self.configureSession()
self.captureSession.startRunning()
}
和
let dataOutput = AVCaptureVideoDataOutput()
dataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue"))
captureSession.addOutput(dataOutput)
确保您签出了这篇中篇文章(由于部分代码已过时,请阅读第二条评论)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句