diff --git a/ios/ExpoAudioStreamModule.swift b/ios/ExpoAudioStreamModule.swift index 413b1ce..329120e 100644 --- a/ios/ExpoAudioStreamModule.swift +++ b/ios/ExpoAudioStreamModule.swift @@ -28,12 +28,11 @@ public class ExpoAudioStreamModule: Module { private func configureAudioSession() { do { - let audioSession = AVAudioSession.sharedInstance() - try audioSession.setCategory(.playback, mode: .default, options: .defaultToSpeaker) - try audioSession.setActive(true, options: .notifyOthersOnDeactivation) - try audioSession.overrideOutputAudioPort(.speaker) + let audioSession = AVAudioSession.sharedInstance() + try audioSession.setCategory(.playAndRecord, mode: .default, options: [.allowBluetooth, .mixWithOthers]) + try audioSession.setActive(true) } catch { - print("Error configuring audio session: \(error)") + print("Error configuring audio session: \(error)") } } @@ -210,7 +209,8 @@ public class ExpoAudioStreamModule: Module { private func updateAudioRoute() { let audioSession = AVAudioSession.sharedInstance() let headphonesConnected = audioSession.currentRoute.outputs.contains { $0.portType == .headphones || $0.portType == .bluetoothA2DP } - // try? audioSession.overrideOutputAudioPort(headphonesConnected ? .none : .speaker) + try? audioSession.setPreferredInput(nil) + try? audioSession.overrideOutputAudioPort(headphonesConnected ? .none : .speaker) print("updateAudioRoute: \(headphonesConnected)") } @@ -249,6 +249,7 @@ public class ExpoAudioStreamModule: Module { OnCreate { self.setupAudioEngine() self.monitorAudioRouteChanges() + self.updateAudioRoute() } } } diff --git a/package.json b/package.json index a095ff6..ba509f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mykin-ai/expo-audio-stream", - "version": "0.1.7", + "version": "0.1.8", "description": "Expo Audio Stream module", "main": "build/index.js", "types": "build/index.d.ts",