big-author-39928
08/06/2025, 2:09 PMrefined-appointment-81829
08/06/2025, 3:04 PMAVAudioSession management, where both expo-video and LiveKit are competing for audio session control. LiveKitReactNativeModule.swift:29-35 LiveKit automatically configures the audio session for playAndRecord category with specific options, but expo-video may be interfering with this configuration.
LiveKit's Audio Session Management
LiveKit's iOS implementation automatically manages the audio session through several mechanisms:
1. Default Configuration: LiveKitReactNativeModule.swift:29-35 The SDK sets up playAndRecord category with options for Bluetooth, AirPlay, and speaker routing.
2. Dynamic Category Enforcement: index.tsx:46-61 When getUserMedia is called for audio, LiveKit automatically switches to playAndRecord category.
3. Custom Audio Configuration: LiveKitReactNativeModule.swift:120-179 You can override audio settings using setAppleAudioConfiguration, including the mixWithOthers option you mentioned.
Recommended Solutions
1. Use mixWithOthers Audio Category Option
Configure LiveKit to allow audio mixing with other apps: LiveKitReactNativeModule.swift:138-139
import { AudioSession } from '@livekit/react-native';
await AudioSession.setAppleAudioConfiguration({
audioCategoryOptions: ['mixWithOthers', 'allowBluetooth', 'allowBluetoothA2DP', 'defaultToSpeaker']
});
2. Coordinate Audio Session Timing
Since you mentioned starting video playback before the call works (though flaky), try this sequence:
1. Start expo-video playback first
2. Configure LiveKit's audio session with mixWithOthers
3. Then start the LiveKit audio session
3. Use iOS Audio Management Hook
For more sophisticated audio session management, consider using the useIOSAudioManagement hook: RoomPage.tsx:30 This hook automatically adjusts audio configuration based on track states and can help coordinate with other audio sources.
Additional Troubleshooting
1. Check Audio Session State: Monitor when audio session changes occur by adding logging around your expo-video and LiveKit initialization.
2. Test Category Options: Try different combinations of audioCategoryOptions in setAppleAudioConfiguration to find the optimal configuration for your use case.
3. Consider Audio Interruption Handling: iOS may be treating the competing audio sessions as interruptions, causing the microphone to deactivate.
Notes
The issue is specific to iOS due to its strict AVAudioSession management. README.md:156-161 LiveKit automatically manages the audio session and switches between playback and playAndRecord categories based on local stream publishing. The mixWithOthers category option should allow both expo-video and LiveKit to coexist, but timing and configuration order matter significantly on iOS.big-author-39928
08/06/2025, 3:50 PM