startVideoStreaming method

Future<void> startVideoStreaming(
  1. String url, {
  2. int bitrate = 1200 * 1024,
  3. required bool androidUseOpenGL,
  4. int? width,
  5. int? height,
})

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> startVideoStreaming(String url,
    {int bitrate = 1200 * 1024,
    required bool androidUseOpenGL,
    int? width,
    int? height}) 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.',
    );
  }

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