startVideoRecording method

Future<void> startVideoRecording(
  1. String filePath
)

Start a video recording and save the file to path.

A path can for example be obtained using path_provider.

The file is written on the flight as the video is being recorded. If a file already exists at the provided path an error will be thrown. The file can be read as soon as stopVideoRecording returns.

Throws a CameraException if the capture fails.

Implementation

Future<void> startVideoRecording(String filePath) async {
  if (!value.isInitialized! || _isDisposed) {
    throw CameraException(
      'Uninitialized CameraController',
      'startVideoRecording was called on uninitialized CameraController',
    );
  }
  if (value.isRecordingVideo!) {
    throw CameraException(
      'A video recording is already started.',
      'startVideoRecording was called when a recording is already started.',
    );
  }
  if (value.isStreamingImages!) {
    throw CameraException(
      'A camera has started streaming images.',
      'startVideoRecording was called while a camera was streaming images.',
    );
  }

  try {
    await _channel.invokeMethod<void>(
      'startVideoRecording',
      <String, dynamic>{'textureId': _textureId, 'filePath': filePath},
    );
    value = value.copyWith(isRecordingVideo: true, isRecordingPaused: false);
  } on PlatformException catch (e) {
    throw CameraException(e.code, e.message);
  }
}