join us on Discord for support, updates, and all things Snap AR! See you there!
Preventing AVAudioSession Interruption with Camera Kit SDK: Seeking Solutions and Best Practices
Issue Description:
The Camera Kit SDK is overriding the AVAudioSession
category, which interrupts current audio playback from other apps. Forcing session.setActive(true)
does not continue playback. We aim to configure the camera controller without interrupting audio playback, similar to the behavior of the native Snapchat app.
Workaround Attempt:
We tried the following workaround by setting the audio session category each time a lens is applied in the completion of CameraController.applyLens(_:completion)
. This allowed audio playback from other apps to be captured correctly.
let _session = AVAudioSession.sharedInstance() try _session.setCategory( AVAudioSession.Category.playAndRecord, mode: AVAudioSession.Mode.videoRecording, options: [.mixWithOthers] ) try _session.setActive(true, options: .notifyOthersOnDeactivation)
Current Issue:
This workaround does not work in the following scenario:
cameraController?.configure( orientation: .portrait, textInputContextProvider: nil, agreementsPresentationContextProvider: presentationProvider ) { completion() }
Initial camera recording, without lenses, does not capture any audio playback. However, after selecting a lens, the audio playback is captured.
Actual Result:
CameraController.configure
results in third-party audio playback stopping.- Camera recording starts, but the video output has no sound at all.
Expected Result:
CameraController.configure
should not affect the currentAVAudioSession
.- Camera recording should start with mixed sound inputs (audio playback, voice, noise, etc.) and not stop any third-party app's audio playback initially or in photo/video capturing mode.
Additional Information:
We are investigating how to avoid modifying the AVAudioSession
in the SDK. Any guidance or updates on this matter would be appreciated.