onStop method

  1. @override
Future<bool> onStop()
override

Callback when this executor is stopped. Returns true if successfully stopped, false otherwise.

Implementation

@override
Future<bool> onStop() async {
  // when stopping the audio sampling, stop recording and collect the measurement
  if (_isRecording) {
    try {
      await _stopAudioRecording();

      var measurement = _data != null
          ? Measurement(
              sensorStartTime:
                  _data!.startRecordingTime!.microsecondsSinceEpoch,
              sensorEndTime: _data!.endRecordingTime?.microsecondsSinceEpoch,
              data: _data!)
          : null;

      if (measurement != null) addMeasurement(measurement);
      debug('Audio recording stopped - sound file : $_soundFileName');
    } catch (error) {
      warning('An error occurred trying to stop audio recording - $error');
      addError(error);
    }
  }
  return true;
}