stopRecordingVideo method

Future<void> stopRecordingVideo()

Stop the recording process. 停止录制视频

Implementation

Future<void> stopRecordingVideo() async {
  if (isControllerBusy) {
    return;
  }

  recordStopwatch.stop();
  if (innerController == null || !controller.value.isRecordingVideo) {
    recordCountdownTimer?.cancel();
    safeSetState(() {
      isControllerBusy = false;
      isShootingButtonAnimate = false;
    });
    return;
  }
  safeSetState(() {
    isControllerBusy = true;
    lastShootingButtonPressedPosition = null;
  });
  try {
    final XFile file = await controller.stopVideoRecording();
    if (recordStopwatch.elapsed < minimumRecordingDuration) {
      pickerConfig.onMinimumRecordDurationNotMet?.call();
      return;
    }
    controller.pausePreview();
    final bool? isCapturedFileHandled = pickerConfig.onXFileCaptured?.call(
      file,
      CameraPickerViewType.video,
    );
    if (isCapturedFileHandled ?? false) {
      return;
    }
    final AssetEntity? entity = await pushToViewer(
      file: file,
      viewType: CameraPickerViewType.video,
    );
    if (entity != null) {
      Navigator.of(context).pop(entity);
    } else {
      await controller.resumePreview();
    }
  } catch (e, s) {
    recordCountdownTimer?.cancel();
    initCameras();
    handleErrorWithHandler(e, s, pickerConfig.onError);
  } finally {
    safeSetState(() {
      isControllerBusy = false;
      isShootingButtonAnimate = false;
    });
  }
}