How to play multiple video in grid view flutter?

1.5k Views Asked by At
 VideoPlayerController _controller;
  Future<void> _initializeVideoPlayerFuture;
   @override
  void initState() {

  
      _controller = VideoPlayerController.network(widget.post.downloadURL[0])
        ..setLooping(true)
        ..play()
        ..setVolume(0);
      _initializeVideoPlayerFuture = _controller.initialize();
    

    super.initState();
  }
  @override
  Widget build(BuildContext context) {



return FutureBuilder(
                  future: _initializeVideoPlayerFuture,
                  builder: (context, snapshot) {
                    if (snapshot.connectionState == ConnectionState.done) {
                      return AspectRatio(
                          aspectRatio: _controller.value.aspectRatio,
                          child: VideoPlayer(_controller));
                    } else {
                      return Center(child: CircularProgressIndicator());
                    }
                  },
                );


    
  }
}

The above code is a child of gridView Builder which is a child of FutureBuilder (which gets data from firestore). I want to play all the videos at once. I tried with the above method but only one video play and rest all stops. The layout is similar to the Instagram search section. Is there any way to play multiple videos at once?
video packaged used here is video_player:

1

There are 1 best solutions below

0
On

I did a list of controllers looping over the items of the grid, then instead of _controller use _controllers[index]