4

I'm using the flutter video_player to display videos in a loop. I show a loading indicator as long as the video player is not initialized yet. The problem is that after initialize().then() is called, the video still needs about 3 - 5 seconds until it plays the video.

Another problem is that I want to play the video in a loop. I cut the video in such a way that no transition can be seen in the loop. The problem is that the video_player shortly stops the video and then restarts it.

Does someone have an idea if I can make any improvements to get the desired result?

Here is my code:

  void initVideo() {
    setState(() {
      isLoading = true;
    });

    _controller = VideoPlayerController.network(
      videoUrl,
    );

    _controller!.addListener(() {
      setState(() {});
    });

    _controller!.initialize().then((_) async {
      setState(() {
        _controller!.play();
        isLoading = false;
      });
    });

    _controller!.setLooping(true);
    _controller!.setVolume(0.0);
  }
saibot
  • 331
  • 2
  • 13
  • First issue might be about your internet connection, and second one shouldn't happen at all :/ – Alperen Ekin Jun 02 '22 at 14:18
  • I think that second issue might be related to the first one. There is a bug (https://github.com/flutter/flutter/issues/99417) in video_player library which makes it re-download video every time you loop it. For me it seems like since your connection is weak, it just takes time for the device to redownload the beginning of the video every time. – Karzel Aug 22 '22 at 04:53

0 Answers0