stopVideoRecording method

void stopVideoRecording()

Implementation

void stopVideoRecording() async {
  if (!initialized) {
    _uiHandler.showSnackBar('Couldn\'t find the camera!');
    return;
  }

  if (value.isRecordingVideo) {
    try {
      final xFile = await controller.stopVideoRecording();
      final file = File(xFile.path);
      final entity = await PhotoManager.editor.saveVideo(
        file,
        title: path.basename(file.path),
      );
      if (file.existsSync()) {
        file.deleteSync();
      }

      value = value.copyWith(isRecordingVideo: false);

      if (entity != null) {
        final d = await entity.thumbnailData;
        final mediaEntity = MediaEntity(entity: entity, bytes: d!);
        await SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
            overlays: SystemUiOverlay.values);
        _uiHandler.pop<MediaEntity>(mediaEntity);
        return;
      } else {
        _uiHandler.showSnackBar('Something went wrong! Please try again');
        return;
      }
    } on CameraException catch (e) {
      _uiHandler.showExceptionSnackbar(e);

      value = value.copyWith(isRecordingVideo: false);
      rethrow;
    }
  } else {
    _uiHandler.showSnackBar('Recording not found!');
    return;
  }
}