broad-agency-36763
12/12/2025, 12:10 PMtall-airline-16756
12/12/2025, 12:10 PMtall-airline-16756
12/12/2025, 12:11 PMuseroom.startAudio — are you also re-establishing the Room/PeerConnection or re-publishing tracks?)
2. Device model, OS versions, and LiveKit Flutter SDK version.
What I recommend trying next (pick whichever fits your app):
• Ensure iOS background-audio entitlement is set if you need audio while backgrounded.
• On app resume, check ICE/PC state and if disconnected, reconnect the Room (call Room.connect or recreate the Room/PC) and re-publish tracks.
• If ICE is still connected but audio is silent, explicitly stop and re-create the local audio track, then publish it again.
• Log WebRTC/ICE states and track muted/enabled flags to confirm whether audio transport or just routing is affected.
Send me the answers to 1–6 and any logs you can capture when resuming; I’ll propose exact code snippets for your recovery flow.
Sources: Enhanced noise cancellation | LiveKit docs | Flutter quickstart | LiveKit docs | Camera & microphone | LiveKit docs | Swift quickstart | LiveKit docs | client-sdk-flutter | livekit/livekit_composite | DeepWikibroad-agency-36763
12/12/2025, 12:15 PMtall-airline-16756
12/12/2025, 12:15 PMstartAudio and re-subscribing.
Likely cause
• iOS is interrupting or changing the native audio session / routing or the WebRTC transport; simply re-subscribing or calling startAudio may not reinitialize the native AVAudioSession or peer connection state.
Actionable steps to try now
1. On app resume, explicitly reconfigure and activate AVAudioSession before restoring tracks:
◦ Set category to playAndRecord with .defaultToSpeaker and activate the session.
◦ Example flow (pseudo):
▪︎ configure AVAudioSession: setCategory(.playAndRecord, options: .defaultToSpeaker)
▪︎ try AVAudioSession.sharedInstance().setActive(true)
1. After AVAudioSession is active, recreate and re-publish the local audio track instead of only calling `startAudio`:
◦ Stop current local audio track if exists.
◦ Create a new local audio track (via LiveKit Flutter API) and publish it.
◦ Then re-subscribe to remote audio tracks / ensure remote subscriptions are enabled.
1. If ICE/PeerConnection appears connected but audio is silent, perform a lightweight renegotiate:
◦ Call your Room.disconnect() and then reconnect, or trigger a track replace / re-offer so the peer connection renegotiates.
1. Add lifecycle wiring in Flutter:
◦ On AppLifecycleState.paused: optionally pause UI but keep room active if you rely on background audio.
◦ On AppLifecycleState.resumed: run the AVAudioSession activation + track recreate + resubscribe/renegotiate sequence.
1. Add logs to confirm sequence:
◦ Log AVAudioSession category/active state, local track `isMuted`/`isEnabled`, and Room/PC ICE connection state when resuming.
What I can help next
• I can provide concrete Flutter + native iOS code snippets (Swift for AVAudioSession and Flutter-side sequence) if you want.
• If you can share logs showing AVAudioSession state or LiveKit track publish events at resume, I can point to the exact spot to change.
Would you like the Swift + Flutter code snippets to implement steps 1–3?broad-agency-36763
12/12/2025, 12:16 PMtall-airline-16756
12/12/2025, 12:17 PMimport AVFoundation
func configureAndActivateAudioSession() throws {
let session = AVAudioSession.sharedInstance()
try session.setCategory(.playAndRecord, options: [.defaultToSpeaker, .allowBluetooth])
try session.setMode(.voiceChat)
try session.setActive(true, options: [])
}
func deactivateAudioSession() {
let session = AVAudioSession.sharedInstance()
try? session.setActive(false, options: [])
}
Flutter side — lifecycle wiring (Dart)
import 'package:flutter/widgets.dart';
import 'package:livekit_client/livekit_client.dart';
import 'package:flutter/services.dart';
class MyAppLifecycleHandler extends WidgetsBindingObserver {
final Room room;
static const platform = MethodChannel('com.example.app/audio');
MyAppLifecycleHandler(this.room);
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
_onResume();
}
}
Future<void> _onResume() async {
// 1) Ensure native AVAudioSession is configured
try {
await platform.invokeMethod('configureAudioSession');
} catch (e) {
print('configureAudioSession error: $e');
}
// 2) Recreate local audio track and publish/replace
try {
final localParticipant = room.localParticipant;
if (localParticipant == null) return;
// stop existing audio tracks
for (var pub in localParticipant.audioTracks) {
await pub.stopTrack(); // or stop the underlying track if available
}
// create new track
final newTrack = await LocalAudioTrack.createTrack();
await localParticipant.publishTrack(newTrack);
// 3) Ensure subscriptions are enabled for remote audio
for (var p in room.participants.values) {
for (var sub in p.audioTracks) {
if (sub.subscriptionStatus != SubscriptionStatus.subscribed) {
await sub.setSubscribed(true);
}
}
}
} catch (e) {
print('audio restore error: $e');
}
// 4) Optionally check ICE / connection state and reconnect if needed
if (room.connectionState != ConnectionState.connected) {
try {
await room.disconnect();
// reconnect flow depends on your app - obtain token and call connect
} catch (e) {
print('reconnect error: $e');
}
}
}
}
Android/iOS bridge — Swift method channel handler
// AppDelegate.swift
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
private let channelName = "com.example.app/audio"
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let audioChannel = FlutterMethodChannel(name: channelName, binaryMessenger: controller.binaryMessenger)
audioChannel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) in
if call.method == "configureAudioSession" {
do {
try configureAndActivateAudioSession()
result(nil)
} catch {
result(FlutterError(code: "AUDIO_ERROR", message: error.localizedDescription, details: nil))
}
} else {
result(FlutterMethodNotImplemented)
}
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Notes and tips
• Use .voiceChat mode and .allowBluetooth option if Bluetooth headsets are used.
• Replacing the track is usually lighter than full reconnect; prefer localParticipant.replaceTrack(...) if your SDK exposes it.
• Log AVAudioSession.active, AVAudioSession.category, Room connectionState, and local track publish events to verify steps.
• If you still see silent audio with Room.connected and tracks published, try a full reconnect (disconnect + connect) as a fallback.
Would you like a ready-to-drop-in Flutter plugin example that covers full reconnect and track replace flows for your app?