diff --git a/Sources/LiveKit/Track/AudioManager.swift b/Sources/LiveKit/Track/AudioManager.swift index 8d0187ce8..0a9b72ba7 100644 --- a/Sources/LiveKit/Track/AudioManager.swift +++ b/Sources/LiveKit/Track/AudioManager.swift @@ -203,9 +203,10 @@ public class AudioManager: Loggable { // trigger events when state mutates _state.onDidMutate = { [weak self] newState, oldState in guard let self else { return } + // Return if state is equal. + guard newState != oldState else { return } self.log("\(oldState) -> \(newState)") - #if os(iOS) let configureFunc = newState.customConfigureFunc ?? self.defaultConfigureAudioSessionFunc configureFunc(newState, oldState) diff --git a/Sources/LiveKit/Track/Track.swift b/Sources/LiveKit/Track/Track.swift index 039bde41f..8b2252a8a 100644 --- a/Sources/LiveKit/Track/Track.swift +++ b/Sources/LiveKit/Track/Track.swift @@ -351,16 +351,16 @@ extension Track { func _mute() async throws { // LocalTrack only, already muted guard self is LocalTrack, !isMuted else { return } - try await disable() - try await stop() + try await disable() // Disable track first + try await stop() // Stop track set(muted: true, shouldSendSignal: true) } func _unmute() async throws { // LocalTrack only, already un-muted guard self is LocalTrack, isMuted else { return } - try await enable() - try await start() + try await start() // Start track first (Configure session first if local audio) + try await enable() // Enable track set(muted: false, shouldSendSignal: true) } }