client-sdk-flutter icon indicating copy to clipboard operation
client-sdk-flutter copied to clipboard

[bug] iOS Audio Ducking of External Audio (e.g., Ringback Tone) with LiveKit

Open rahulraj-idt opened this issue 7 months ago • 2 comments

Describe the bug On iOS, an external audio stream (e.g., ringback tone via just_audio) is ducked/silenced when a LiveKit room connection is established. Playing a ring back tone is a crucial feature for any VoIP app.

To Reproduce

  • Connect to the room
await room.connect(
     llivekitURL,
     livekitToken,
   )
  • Play ring back tone while waiting for the callee to join
Future<void> startRingbackTone() async {
    try {
      _audioPlayer ??= AudioPlayer();
      await _audioPlayer!.setAsset('.../ringing.mp3');
      await _audioPlayer!.setLoopMode(LoopMode.all);
      await _audioPlayer!.play();
    } catch (e) {
      Log.error('RingbackTonePlayer: Failed to start ringback tone: $e');
    }
  }
  • Then unable to hear the ring back tone since livekit connection ducking external audio (significantly reduced). Expected behavior The audio stream continues to play clearly alongside LiveKit audio. Note that I’ve already tried configuring the WebRTC audio both before and after the LiveKit connection, but the issue persists.
    if (Platform.isIOS) {
      try {
        await webrtc.Helper.setAppleAudioConfiguration(webrtc.AppleAudioConfiguration(
          appleAudioCategory: webrtc.AppleAudioCategory.playAndRecord,
          appleAudioCategoryOptions: {
            webrtc.AppleAudioCategoryOption.mixWithOthers,
            webrtc.AppleAudioCategoryOption.defaultToSpeaker,
            webrtc.AppleAudioCategoryOption.allowBluetooth,
            webrtc.AppleAudioCategoryOption.allowBluetoothA2DP,
          },
          appleAudioMode: webrtc.AppleAudioMode.videoChat,
        ));
        Log.info('LiveKit: iOS audio configuration set for mixing with ringback tone');
      } catch (e) {
        Log.error('LiveKit: Failed to configure iOS audio session: $e');
      }
    }

Platform information iOS 18.4.1

  • Flutter version: 3.24.5
  • Plugin version: livekit_client: ^2.4.7
  • Flutter target OS: iPhone - iOS 18.4.1 ^^ @cloudwebrtc

rahulraj-idt avatar May 23 '25 08:05 rahulraj-idt

did you manage to solve this?

Amrazyan avatar Jun 10 '25 05:06 Amrazyan

You need to set a proper context when you call the method play from the _audioplayer, becuase the iOS env is sharing one audio context per app. Please check the implementation of the player package that you use and investigate what is set by default.

skutimechanic avatar Jun 25 '25 11:06 skutimechanic