Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter video_player Duration?

I am using the Flutter video_player package here: https://pub.dev/packages/video_player

How do I get the duration of the video? I can see there is a position property, so I would need that to get the current value in time.

But how do I get the total duration of the video? The video is from a URL.

I am making a custom player so I need these two values.

like image 939
Jiehfeng Avatar asked Sep 08 '25 00:09

Jiehfeng


1 Answers

For getting the Total duration you can use the video controller

 VideoPlayerController _controller = VideoPlayerController.network('https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4')
      ..initialize().then((_) {
        // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
      });

 Duration durationOfVideo = _controller.value.duration;

You can also directly store the integer instead of duration as below image

enter image description here

like image 135
Sheetal Savani Avatar answered Sep 10 '25 16:09

Sheetal Savani