useNetworkVideo function

VideoPlayerController useNetworkVideo({
  1. required String dataSource,
  2. bool autoPlay = false,
  3. bool looping = false,
  4. Future<ClosedCaptionFile>? closedCaptionFile,
  5. VideoPlayerOptions? videoPlayerOptions,
  6. Map<String, String> httpHeaders = const {},
})

Creates VideoPlayerController using video_player(ref link), plays video obtained from the network, tracks its state, and exposes playback controls. ref link

Implementation

VideoPlayerController useNetworkVideo({
  required String dataSource,
  bool autoPlay = false,
  bool looping = false,
  Future<ClosedCaptionFile>? closedCaptionFile,
  VideoPlayerOptions? videoPlayerOptions,
  Map<String, String> httpHeaders = const {},
}) {
  final controller = useMemoized(
    () => VideoPlayerController.networkUrl(
      Uri.parse(dataSource),
      closedCaptionFile: closedCaptionFile,
      videoPlayerOptions: videoPlayerOptions,
      httpHeaders: httpHeaders,
    ),
    [dataSource, closedCaptionFile, videoPlayerOptions, httpHeaders],
  );

  useEffect(
    () {
      controller
        ..initialize()
        ..setLooping(looping);

      if (autoPlay) {
        controller.play();
      }

      return controller.dispose;
    },
    [dataSource, closedCaptionFile, videoPlayerOptions, httpHeaders],
  );

  return controller;
}