stopCapture method

Future<void> stopCapture()

Stops capturing system audio.

This method will stop the active capture and close all associated streams. If capture is not active, this method does nothing.

Throws an Exception if stopping fails.

Example:

await systemCapture.startCapture();

// ... use audio stream ...

await systemCapture.stopCapture();
print('System audio capture stopped');

Implementation

Future<void> stopCapture() async {
  if (!_isRecording) return;

  try {
    final stopped = await _channel.invokeMethod<bool>(
      _SystemAudioMethod.stopCapture.name,
    );

    if (stopped != true) {
      throw Exception("Failed to stop system audio capture");
    }

    _isRecording = false;
    _audioStream = null;
    _statusStream = null;
    _decibelStream = null;
  } catch (e) {
    rethrow;
  }
}