I developed a custom camera functionality using Apple's sample code AVCAM and in my application the background modes are enabled which is causing red bar issue.
I create AVCaptureSession and then add inputs(.Video,.Audio) and outputs in session.
Below is code to add audio input in session
var audioDeviceInput:AVCaptureDeviceInput!
guard let audioDevice = AVCaptureDevice.default(for: AVMediaType.audio) else { return }
do {
audioDeviceInput = try AVCaptureDeviceInput(device: audioDevice)
} catch let error {
audioDeviceInput = nil
NSLog("Could not create audio device input: \(error)")
}
self.session.addInput(audioDeviceInput)
Now when user presses home button, the red bar flashes on iPhone screen for milliseconds and then disappear(indicating the mic is being used) and i want to avoid this red bar.
After doing some R&D i came to know this is happening because of audio input added in session (the code of adding audio input is mention above)
What i have done so far is? To resolve this issue, I only adding audio input when user starts recording video and remove audio input when user stops video. This actually resolved the red bar problem but this happens to cause jerk in preview which is really irritating. Now, i want to resolve this UI jerk but doesn't know how to do this.
Any help will be appreciated.