Home > other >  How can get video player duration in flutter?
How can get video player duration in flutter?

Time:11-23

How can I get video duration without

https://pub.dev/packages/video_player

package or base this player. Is there any other way?

video player duration

CodePudding user response:

You can use ffmpeg package for the same, just do:

    class ClassName {
      final FlutterFFmpeg _flutterFFmpeg = new FlutterFFmpeg();
        ...
      void someFunction() {
        _flutterFFmpeg
            .getMediaInformation("<file path or uri>")
            .then((info) => print(info));
      }
    }

CodePudding user response:

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;
  • Related