useAssetVideo function

VideoPlayerController useAssetVideo({
  1. required String asset,
  2. String? package,
  3. bool autoPlay = false,
  4. bool looping = false,
  5. Future<ClosedCaptionFile>? closedCaptionFile,
  6. VideoPlayerOptions? videoPlayerOptions,
})

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

Implementation

VideoPlayerController useAssetVideo({
  required String asset,
  String? package,
  bool autoPlay = false,
  bool looping = false,
  Future<ClosedCaptionFile>? closedCaptionFile,
  VideoPlayerOptions? videoPlayerOptions,
}) {
  final controller = useMemoized(
    () => VideoPlayerController.asset(
      asset,
      package: package,
      closedCaptionFile: closedCaptionFile,
      videoPlayerOptions: videoPlayerOptions,
    ),
    [asset, package, closedCaptionFile, videoPlayerOptions],
  );

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

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

    return controller.dispose;
  }, [asset, package, closedCaptionFile, videoPlayerOptions]);

  return controller;
}