startVideoRecordingAndStreaming method

Future<void> startVideoRecordingAndStreaming(
  1. String? filePath,
  2. String? url, {
  3. int bitrate = 1200 * 1024,
  4. bool? androidUseOpenGL,
})

Start a video streaming to the url in url`.

This uses rtmp to do the sending the remote side.

Throws a CameraException if the capture fails.

Implementation

Future<void> startVideoRecordingAndStreaming(String? filePath, String? url,
    {int bitrate = 1200 * 1024, bool? androidUseOpenGL}) async {
  if (!value.isInitialized! || _isDisposed) {
    throw CameraException(
      'Uninitialized CameraController',
      'startVideoStreaming was called on uninitialized CameraController',
    );
  }

  if (value.isRecordingVideo) {
    throw CameraException(
      'A video recording is already started.',
      'startVideoStreaming was called when a recording is already started.',
    );
  }
  if (value.isStreamingVideoRtmp) {
    throw CameraException(
      'A video streaming is already started.',
      'startVideoStreaming was called when a recording is already started.',
    );
  }
  if (value.isStreamingImages) {
    throw CameraException(
      'A camera has started streaming images.',
      'startVideoStreaming was called while a camera was streaming images.',
    );
  }

  if (filePath == null || url == null) {
    throw CameraException(
        "Null arguments",
        "URL $url and path $filePath need to be not null to start "
            "streaming and recording");
  }

  try {
    await _channel.invokeMethod<void>(
        'startVideoRecordingAndStreaming', <String, dynamic>{
      'textureId': _textureId,
      'url': url,
      'filePath': filePath,
      'bitrate': bitrate,
    });
    value =
        value.copyWith(isStreamingVideoRtmp: true, isStreamingPaused: false);
  } on PlatformException catch (e) {
    throw CameraException(e.code, e.message!);
  }
}