DAVID TEC
DAVID TEC

Reputation: 387

Track progress Flutter video player

Hi I'm using the flutter video player plugin, I have something similar like this [{phrase:"something", startAt: 1039}, {phrase:"other somthing", startAt: 26500}] is there a way to change in ui the phrase based on the start time while the video is playing.

I have try to use a timer with a duration of 100 ms but I retrieve no exact time from the Flutter video player plugin.

Upvotes: 3

Views: 6739

Answers (1)

Adrian Avram
Adrian Avram

Reputation: 957

You probably want to take a look at stateful widgets as they allow you to do exactly this. In short, you can set phrase to be some variable and once the video starts you can call setState and change the variable. Flutter will automatically redraw the widget and the text will be updated.

To determine if the video player is playing you can add a listener to your video controller.

_controller = VideoPlayerController.network(
      'http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_20mb.mp4',
    )
      ..addListener(() {
        final bool isPlaying = _controller.value.isPlaying;
        if (isPlaying != _isPlaying) {
          setState(() {
            _isPlaying = isPlaying;
          });
        }
      })
      ..initialize().then((_) {
        // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
        setState(() {});
      });

Upvotes: 11

Related Questions