startVideoRecording method

Future<void> startVideoRecording({
  1. onLatestImageAvailable? onAvailable,
})

Start a video recording.

You may optionally pass an onAvailable callback to also have the video frames streamed to this callback.

The video is returned as a XFile after calling stopVideoRecording. Throws a CameraException if the capture fails.

Implementation

Future<void> startVideoRecording(
    {onLatestImageAvailable? onAvailable}) async {
  _throwIfNotInitialized('startVideoRecording');
  if (value.isRecordingVideo) {
    throw CameraException(
      'A video recording is already started.',
      'startVideoRecording was called when a recording is already started.',
    );
  }

  void Function(CameraImageData image)? streamCallback;
  if (onAvailable != null) {
    streamCallback = (CameraImageData imageData) {
      onAvailable(CameraImage.fromPlatformInterface(imageData));
    };
  }

  try {
    await CameraPlatform.instance.startVideoCapturing(
        VideoCaptureOptions(_cameraId, streamCallback: streamCallback));
    value = value.copyWith(
        isRecordingVideo: true,
        isRecordingPaused: false,
        recordingOrientation: Optional<DeviceOrientation>.of(
            value.lockedCaptureOrientation ?? value.deviceOrientation),
        isStreamingImages: onAvailable != null);
  } on PlatformException catch (e) {
    throw CameraException(e.code, e.message);
  }
}