Flutter: chewie using in Listview

309 views Asked by At

I have a json data. json data contains a lof of video link. for example:

[{"id": 12, "name": "bryn", "link":"https://www.xxxxx.com/videos/asdasfrlşr.mp4"},{"id": 13, "name": "brynas", "link":"https://www.xxxxx.com/videos/fgfasfrlşr.mp4"},{"id": 14, "name": "e3bryn", "link":"https://www.xxxxx.com/videos/asdasfthvbvbr.mp4"}]

I use Chewie video player. I can list that videos and I can watch. but I close that page. video is not close. Video plays background. My code is below.

VideoPlayerController _videoPlayerController1;
ChewieController _chewieController;

@override
  void initState() {
    super.initState();
    _videoPlayerController1 = VideoPlayerController.network(
        products[index]["link"]);
    _chewieController = ChewieController(
      videoPlayerController: _videoPlayerController1,
      aspectRatio: 16 / 9,
      autoPlay: true,
      looping: true,
      // Try playing around with some of these other options:

      // showControls: false,
      // materialProgressColors: ChewieProgressColors(
      //   playedColor: Colors.red,
      //   handleColor: Colors.blue,
      //   backgroundColor: Colors.grey,
      //   bufferedColor: Colors.lightGreen,
      // ),
      // placeholder: Container(
      //   color: Colors.grey,
      // ),
      // autoInitialize: true,
    );
  }

  @override
  void dispose() {
    _videoPlayerController.dispose();
    _chewieController.dispose();
    super.dispose();
  }

ListView.builder(
    itemCount: products == null ? 0 : products.length,
    itemBuilder: (BuildContext asd, int index) => Container(
        child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
           children: [
               Padding(
               padding: const EdgeInsets.all(8.0),
                  child: RichText(
                     text: TextSpan(
                        children: [
                             TextSpan(
                                text: products[index]["yazi"],
                                style: TextStyle(
                                   fontSize: 16,
                                      color: localStorage.mainColor,
                                      fontWeight: FontWeight.bold)),
                                  ],
                                ),
                              ),
                            ),
                    products[index]["link"] == "" ? Text("Video did not found !",
                           style: TextStyle(
                             color: localStorage.mainColor,
                             fontSize: 18,
                              fontWeight: FontWeight.bold),
                          ) : Chewie(controller: _chewieController),
                             SizedBox(height: 10),])))

How can I solve this problem. thanks.

0

There are 0 answers