captureOutput not being called
You made a mistake in declaration of required sample buffer delegate method:
captureOutput(_:didOutputSampleBuffer:from:)
.
Please check it and make sure it is:
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!)
PS: Pay attention on how parameters of that method are declared. All parameters have '!' which means automatic unwrapping.
AVCaptureVideoDataOutput captureOutput not being called
You need to define the didOutputSampleBuffer
delegate callback to actually receive the captured frames:
func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
print("captured \(sampleBuffer)")
}
p.s. I'm not sure about macOS, but viewWillAppear
may not be a good place to do initialisation because on iOS at least it can be called multiple times.
captureOutput not being called by AVCaptureAudioDataOutputSampleBufferDelegate
Ok, nobody got back to me but after playing around with it I worked out the correct way to declare the captureOutput method for Swift4 is as follows:
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
//Do your stuff here
}
Unfortunately, the documentation for this online is very poor. I guess you just need to get it exactly right - there are no errors thrown if you mispell or misname the variables as it is an optional function.
captureOutput from AVCaptureVideoDataOutputSampleBufferDelegate is not being called
You are missing adding the input
if session.canAddInput(videoDeviceInput){
session.addInput(videoDeviceInput)
}
captureOutput not being called from delegate
Update: There is actually nothing wrong with the code here. The issue I was having was that the instance of the class that is described above was being garbage collected.
AVCaptureAudioDataOutput Is Not Calling AVCaptureAudioDataOutputSampleBufferDelegate.captureOutput
Did you get any devices? I tried to build your code but didn't get any devices. Anyway, you can look at this answer and also this answer. Also, one thing I can guess, not sure though. Put your capture session variable
let session = AVCaptureSession()
outside of viewDidLoad.
Related Topics
Use Multiple Codingkeys for a Single Property
Instance Member Cannot Be Used on Type Class
Why Does Int(Float(Int.Max)) Give Me an Error
Appending Tuples to an Array of Tuples
Why Is Swift's Ternary Operator So Picky About Whitespace
Get Lat and Long from Tapped Overlay in Google Maps
Build Input File Cannot Be Found' Swift 4.2, Xcode 10.0
Xcode Playgrounds Can't Access Swift Files in Sources Folder
How to Reset Intent Extension Configurations in Widgetkit
Why Does Swiftui Uihostingcontroller Have Extra Spacing
Rotating a Cgpoint Around Another Cgpoint
How to Stream Remote Audio in iOS 13? (Swiftui)
Swift- Variable Not Initialized Before Use (But It's Not Used)
Hot to Decode JSON Data That Could and Array or a Single Element in Swift
Having Tab Bar and Navigationbar in the Same View in Swiftui