Swift, Avaudiorecorder: Error 317: Ca_Debug_String: Inpropertydata == Null

AVAudioRecorder not working

In Swift you don't provide the error parameter since it throws.

Change this:

soundRecorder = try AVAudioRecorder(url: getFileURL() as URL, settings: recordSettings, error: &error)

to:

soundRecorder = try AVAudioRecorder(url: getFileURL() as URL, settings: recordSettings)

CMSampleBufferGetImageBuffer returning null

After hours of debugging, it turns out that the sample might be a video or audio sample. So trying to get CVPixelBufferRef from an audio buffer returns null.

I solved it by checking the sample type before proceeding. Since I am not interested in the audio samples I simply return when its an audio sample.

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {

CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

CMFormatDescriptionRef formatDesc = CMSampleBufferGetFormatDescription(sampleBuffer);
CMMediaType mediaType = CMFormatDescriptionGetMediaType(formatDesc);

//Checking sample type before proceeding
if (mediaType == kCMMediaType_Audio)
{return;}

//Processing the sample...

}


Related Topics



Leave a reply



Submit