livekit / client-sdk-swift

LiveKit Swift Client SDK. Easily build live audio or video experiences on iOS, macOS, tvOS, and visionOS.
https://livekit.io
Apache License 2.0
188 stars 93 forks source link

Cannot play sound effects while connecting or disconnecting a call #439

Open dfed opened 1 month ago

dfed commented 1 month ago

Describe the bug Enabling or disabling the microphone on a LiveKit room affects the audio stack such that playing sound effects or background noise across these events is user-visibly broken.

SDK Version 2.0.12

iOS/macOS Version Tried on multiple iOS 17 versions, including most recent at time of writing: 17.5.1.

Xcode Version 15.4.0

Steps to Reproduce

  1. Download + open sample project
  2. Set a valid room and token under the // Set your token here comment
  3. Run app (device or simulator – both repro)
  4. Tap "Play audio"
  5. Tap "Connect" Result: audio audibly glitches when the microphone connects
  6. Tap "Disconnect" Result: audio stops playing entirely
  7. Tap "Stop audio"
  8. Tap "Play audio" again Result: app crashes because the player has not seen an I/O cycle. This is because disconnecting has effectively stopped all audio – calling pause() and then play() on the audio engine after disconnecting fixes this crash.

Expected behavior Background audio can play without distortion or stopping across enabling/disabling the microphone.

Though I'll take a workaround to at a minimum let me play sound effects without distortion.

Screenshots N/A. Sample project attached

Logs N/A. Sample project attached

livekit-swift-example-collection-audio.zip

dfed commented 1 month ago

Upon further testing the audio issues above occur when calling room.connect(...) and room.disconnect(), regardless of whether room.localParticipant.setMicrophone(enabled: true/false) is called, even when AudioManager.shared.customConfigureAudioSessionFunc is set to no-op.