1

I tried to start video inside intiState , but didn't work, then I added it inside the build function and it worked, but now it cant be paused am wondering why :

Below is how I play the video :

@override
  Widget build(BuildContext context) {
    controller!.play();
    ....
}

then , when I try to trigger pause, it no longer pause , is it because of the build method, how best can this be achieved so that the state changes.

Lutaaya Huzaifah Idris
  • 3,596
  • 8
  • 38
  • 77

1 Answers1

0

this problem arises due to the fact that after pausing the video, your code runs again, and because you put controller!.play(); in the build function, it plays it again after each build! you can define one boolean parameter: bool isPlayed = false

then use it in didChangeDependencies as follow:

@override
  void didChangeDependencies() {
    super.didChangeDependencies();
    if(!isPlayed){
       controller!.play();
       setState(() {isPlayed = true;});
    }
  }
Abbasihsn
  • 2,075
  • 1
  • 7
  • 17