Hayden Young
Hayden Young

Reputation: 356

Flutter won't initialise a video from disk

I've downloaded a video to disk but it won't initialise using Video Player (https://pub.dev/packages/video_player).

final future = Downloader.shared
            .getVideoPathFor(
          url: url,
          themeName: themeName,
        )
            .then(
          (value) {
            dLog('file path: $value');
            final file = File(value);
            final videoController = VideoPlayerController.file(file);
            return videoController.initialize().then(
              (value) {
                dLog('video controller initialized');
                return videoController;
              },
            );
          },
        );

It downloads the file fine and the file path becomes something like: Application/9E6FD935-A424-4C1E-99CC-D5834448E45E/Library/Caches/videos/Clean water/clean_water_video.mp4

So I know the file exists and I can see it in Finder if I run this on Simulator.

If I use VideoController.contentUri() then it appears to work but it tells me I'm not allowed to use that on iOS and I can only use it on Android.

I know I can use VideoController.network() but I can't keep downloading the same video over and over across multiple screens like this.

What am I doing wrong?

Even when I do load the video like this (which I got from this video: https://youtu.be/uz4xRnE-UIw?t=596):

final filePath =
        "<path>/Caches/videos/Clean water/clean_water_video.mp4";
    final file = File(filePath);
    controller = VideoPlayerController.file(file)
      ..addListener(() {
        setState(() {});
      })
    ..setLooping(true)
    ..initialize().then((value) {
      controller.play();
    });

the initialise never happens.

Upvotes: 0

Views: 867

Answers (1)

Hayden Young
Hayden Young

Reputation: 356

It turns out that it can't load a file if folders have spaces in the name.

Upvotes: 3

Related Questions