How to jump to frame with flutter video player?

996 views Asked by At

Is it possible to jump to certain timestamp and display the frame without starting the video using flutter video_player?

I was able to change a frame only when I call play immediately after seekTo.

  _videoPlayerController.seekTo(Duration(milliseconds: value));
  _videoPlayerController.play();

I also tried

_videoPlayerController.seekTo(Duration(milliseconds: value));
_videoPlayerController.play();
_videoPlayerController.pause();

but it does not change displayed frame of video.

1

There are 1 answers

0
Luis Cor On

This answer probably comes a bit late, and is totally a hack It shouldn't really be used, but it allowed me to have a similar behaviour

From what I could find, VideoPlayerController doesn't have any way to interact with the video regarding frames, only timestamps with the seekTo method you used. You just need to play and pause with a little delay in between actions and have it wrapped in an async function so that you can wait for the actions to complete, essentially this:

void moveOneFrameForward() async {
//Gets the current time point at where the video is at in a "Duration" type object
var currentTime = await _videoPlayerController.position;
//Seeks to the current time + an interval, in this case 100ms
await _videoPlayerController.seekTo(
Duration(milliseconds: currentTime!.inMilliseconds + 100),
);
//Plays the video so to render a frame
await _videoPlayerController.play();
//Delay so that the frame is rendered
await Future.delayed(Duration(milliseconds: 10));
//Video is paused to display the frame
await _videoPlayerController.pause();
}