解决这个问题需要确保以下几点:
AVCaptureAudioDataOutput
的 sampleBufferDelegate
属性为正确的代理对象。let audioOutput = AVCaptureAudioDataOutput()
audioOutput.sampleBufferDelegate = self
AVCaptureAudioDataOutputSampleBufferDelegate
协议,并实现了对应的方法。class YourDelegateClass: AVCaptureAudioDataOutputSampleBufferDelegate {
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
// 处理音频数据
}
}
let delegateInstance = YourDelegateClass()
AVCaptureAudioDataOutput
实例添加到会话中,并连接到合适的输入和输出。let captureSession = AVCaptureSession()
// 添加音频输入和输出
if captureSession.canAddInput(audioInput) && captureSession.canAddOutput(audioOutput) {
captureSession.addInput(audioInput)
captureSession.addOutput(audioOutput)
}
通过检查以上几点,并确保代理方法已正确实现和设置,你应该能够解决 AVCaptureAudioDataOutput
没有调用代理方法的问题。