startImageStream method

Future<void> startImageStream(
  1. onLatestImageAvailable onAvailable
)

Implementation

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

  try {
    await _channel.invokeMethod<void>('startImageStream');
    value = value.copyWith(isStreamingImages: true);
  } on PlatformException catch (e) {
    throw CameraException(e.code, e.message!);
  }
  const EventChannel cameraEventChannel =
      EventChannel('video_stream/imageStream');
  _imageStreamSubscription =
      cameraEventChannel.receiveBroadcastStream().listen(
    (dynamic imageData) {
      onAvailable(CameraImage._fromPlatformData(imageData));
    },
  );
}