You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently saving a local file from the data provide by Audio Sink and Video Render, when the connection drops I lose the audio, so I'm trying to create an Audio Device class to handle it. Can you provide an example on how to do that?
Steps to Reproduce
Drop the internet connection loss the audio
Code
Here is the code that I'm trying to use to capture the audio by my self.
classLocalRecordingAudioDevice:NSObject{privatevarengineAudioDeviceContext:AudioDeviceContext?letaudioSession=AVAudioSession.sharedInstance()letcaptureSession=AVCaptureSession()overrideinit(){
super.init()setupAudioSession()}privatefunc setupAudioSession(){do{try audioSession.setCategory(.playAndRecord, mode:.default)try audioSession.setActive(true)try audioSession.setInputGain(1)}catch{print("Error setting up audio session: \(error)")}}privatefunc setupCaptureSession(){
guard let microphone =AVCaptureDevice.default(for:.audio)else{print("No microphone available")return}do{letinput=tryAVCaptureDeviceInput(device: microphone)
if captureSession.canAddInput(input){
captureSession.addInput(input)}letoutput=AVCaptureAudioDataOutput()
if captureSession.canAddOutput(output){
captureSession.addOutput(output)}letqueue=DispatchQueue(label:"com.localrecord.audioQueue")
output.setSampleBufferDelegate(self, queue: queue)
captureSession.startRunning()}catch{print("Error setting up capture session: \(error)")}}}extensionLocalRecordingAudioDevice:AVCaptureAudioDataOutputSampleBufferDelegate{func captureOutput(_ output:AVCaptureOutput, didOutput sampleBuffer:CMSampleBuffer, from connection:AVCaptureConnection){
guard let audioDeviceContext = engineAudioDeviceContext else{return}
if let blockBuffer =CMSampleBufferGetDataBuffer(sampleBuffer){varlengthAtOffset=0vartotalLength=0vardataPointer:UnsafeMutablePointer<Int8>?letstatus=CMBlockBufferGetDataPointer(blockBuffer, atOffset:0, lengthAtOffsetOut:&lengthAtOffset, totalLengthOut:&totalLength, dataPointerOut:&dataPointer)
if status == kCMBlockBufferNoErr {
if let data = dataPointer {letint8Buffer= UnsafeMutablePointer<Int8>.allocate(capacity: totalLength)letsizeInBytes=MemoryLayout<Int8>.stride * totalLength
AudioDeviceWriteCaptureData(context: audioDeviceContext, data: data, sizeInBytes:32)
int8Buffer.deallocate()}}}}}extensionLocalRecordingAudioDevice:AudioDevice{func renderFormat()->AudioFormat?{returnAudioFormat(channels:1, sampleRate:44100, framesPerBuffer:16)}func initializeRenderer()->Bool{return false
}func startRendering(context:AudioDeviceContext)->Bool{return false
}func stopRendering()->Bool{return false
}func captureFormat()->AudioFormat?{returnAudioFormat(channels:1, sampleRate:44100, framesPerBuffer:16)}func initializeCapturer()->Bool{return true
}func startCapturing(context:AudioDeviceContext)->Bool{
engineAudioDeviceContext = context
setupCaptureSession()return true
}func stopCapturing()->Bool{
captureSession.stopRunning()
engineAudioDeviceContext =nilreturn true
}}
Expected Behavior
When I lose the connection I need to keep capturing the audio
Actual Behavior
When I lose the connection my video turns muted
Reproduces How Often
All the time
Versions
5.7.0
Video iOS SDK
5.7.0
Xcode
15.0.1
iOS Version
17.0.1
iOS Device
iPhone 13 Pro
The text was updated successfully, but these errors were encountered:
Description
I'm currently saving a local file from the data provide by Audio Sink and Video Render, when the connection drops I lose the audio, so I'm trying to create an Audio Device class to handle it. Can you provide an example on how to do that?
Steps to Reproduce
Drop the internet connection loss the audio
Code
Here is the code that I'm trying to use to capture the audio by my self.
Expected Behavior
When I lose the connection I need to keep capturing the audio
Actual Behavior
When I lose the connection my video turns muted
Reproduces How Often
All the time
Versions
5.7.0
Video iOS SDK
5.7.0
Xcode
15.0.1
iOS Version
17.0.1
iOS Device
iPhone 13 Pro
The text was updated successfully, but these errors were encountered: