Automatically handle Audio interruptions (#113)

* Remove audio device when interruption begins

* Remove ReactLogger:alsoLogToJS

* Fix ReactLogger.logJS calls

* Fix `AVCaptureSessionInterruptionReasonKey` cast
This commit is contained in:
Marc Rousavy
2021-03-29 14:12:04 +02:00
committed by GitHub
parent cd180dc73b
commit 4ea636e0d0
4 changed files with 62 additions and 22 deletions

View File

@@ -48,13 +48,14 @@ extension CameraView {
/**
Configures the CaptureSession and adds the audio device if it has not already been added yet.
*/
private final func addAudioInput() throws {
func addAudioInput() throws {
if audioDeviceInput != nil {
// we already added the audio device, don't add it again
return
}
removeAudioInput()
ReactLogger.log(level: .info, message: "Adding audio input...")
captureSession.beginConfiguration()
guard let audioDevice = AVCaptureDevice.default(for: .audio) else {
throw CameraError.device(.microphoneUnavailable)
@@ -71,11 +72,12 @@ extension CameraView {
/**
Configures the CaptureSession and removes the audio device if it has been added before.
*/
private final func removeAudioInput() {
func removeAudioInput() {
guard let audioInput = audioDeviceInput else {
return
}
ReactLogger.log(level: .info, message: "Removing audio input...")
captureSession.beginConfiguration()
captureSession.removeInput(audioInput)
audioDeviceInput = nil