cancel method

Future<void> cancel()

Cancel the current capture without returning data. Mirrors Swift cancel().

Implementation

Future<void> cancel() async {
  if (!_isRecording) {
    return;
  }
  _stopAudioLevelMonitoring();
  try {
    await _recorder.stop();
  } catch (e) {
    _logger.warning('Failed to cancel capture: $e');
  }
  final recordingPath = _currentRecordingPath;
  _currentRecordingPath = null;
  _isRecording = false;
  if (recordingPath != null) {
    final file = File(recordingPath);
    try {
      if (await file.exists()) {
        await file.delete();
      }
    } catch (_) {
      // Best-effort temp cleanup.
    }
  }
}