Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changes/fix-audio-visualizer-missing-plugin-exception
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patch type="fixed" "MissingPluginException when stopping audio visualizer on Android/iOS"
6 changes: 4 additions & 2 deletions lib/src/track/audio_visualizer_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ class AudioVisualizerNative extends AudioVisualizer {
return;
}

await Native.stopVisualizer(mediaStreamTrack.id!, visualizerId: visualizerId);

// Cancel subscription before native stop, otherwise the native
// StreamHandler is already removed and cancel throws MissingPluginException.
await _streamSubscription?.cancel();
_streamSubscription = null;
_eventChannel = null;

await Native.stopVisualizer(mediaStreamTrack.id!, visualizerId: visualizerId);
}
}

Expand Down
1 change: 1 addition & 0 deletions shared_swift/LiveKitPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public class LiveKitPlugin: NSObject, FlutterPlugin {
}

for processors in audioProcessors.values {
processors.visualizers[visualizerId]?.stop()
processors.visualizers.removeValue(forKey: visualizerId)
}

Expand Down
7 changes: 6 additions & 1 deletion shared_swift/Visualizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ public class Visualizer: NSObject, RTCAudioRenderer, FlutterStreamHandler {
channel?.setStreamHandler(self)
}

deinit {
public func stop() {
_track?.remove(audioRenderer: self)
channel?.setStreamHandler(nil)
}

deinit {
stop()
}

public func render(pcmBuffer: AVAudioPCMBuffer) {
Expand Down