'Add mute unmute to video_player function when video is looping? Flutter app

I wanted to know how to add mute unmute function with looped video without pausing it.

on set state I have

setState(() {});
  controller.setLooping(true);
  controller.play();
  controller.setVolume(0);
});

and on gesture detector of video I put this:

GestureDetector(
      onTap: () {
        setState(() {
          if (controller.value.isPlaying) {
            controller.pause();
            controller.setVolume(0);
          } else {
            controller.play();
            controller.setVolume(1);
          }
        });
      },

but if I take off

 controller.play();
 controller.pause();

does not recognize the function

controller.setVolume(1);
controller.setVolume(0);

at this moment the video is in loop and when touched it pauses, and when touched the second time it starts with audio.

How can I make the video never pause? and always remain in the loop?



Solution 1:[1]

Try this -

    GestureDetector(
              onTap: () {
                if (_controller.value.volume == 0) {//check if volume is already set to 0 (i.e mute)
                  _controller.setVolume(1.0); 
                } else {
//check if volume is already set to 1 (i.e unmute)
                  _controller.setVolume(0.0);
                }
                setState(() {});
              },
    )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ashutosh singh