stopRecordingVideo method

Future<void> stopRecordingVideo()

Stop the recording process. 停止录制视频

Implementation

Future<void> stopRecordingVideo() async {
  void _handleError() {
    _recordCountdownTimer?.cancel();
    isShootingButtonAnimate = false;
    safeSetState(() {});
  }

  if (controller.value.isRecordingVideo) {
    controller.stopVideoRecording().then((XFile file) async {
      final AssetEntity? entity = await CameraPickerViewer.pushToViewer(
        context,
        pickerState: this,
        pickerType: CameraPickerViewType.video,
        previewXFile: file,
        theme: theme,
        shouldDeletePreviewFile: shouldDeletePreviewFile,
        shouldAutoPreviewVideo: shouldAutoPreviewVideo,
      );
      if (entity != null) {
        Navigator.of(context).pop(entity);
      }
    }).catchError((Object e) {
      realDebugPrint('Error when stop recording video: $e');
      realDebugPrint('Try to initialize a new CameraController...');
      initCameras();
      _handleError();
      handleErrorWithHandler(e, widget.onError);
    }).whenComplete(() {
      isShootingButtonAnimate = false;
      safeSetState(() {});
    });
    return;
  }
  _handleError();
}