esfsef
esfsef

Reputation: 213

Duration range video player in flutter

I am using video_player package to show my video, and now want set starting and finishing positions for my video, how can I do it?

Upvotes: 1

Views: 3580

Answers (1)

Lulupointu
Lulupointu

Reputation: 3584

seekTo is what you are looking for:

_controller.seekTo(Duration(seconds: 10));

From the source code:

  /// Sets the video's current timestamp to be at [moment]. The next
  /// time the video is played it will resume from the given [moment].
  ///
  /// If [moment] is outside of the video's full range it will be automatically
  /// and silently clamped.
  Future<void> seekTo(Duration position) async {
    if (_isDisposed) {
      return;
    }
    if (position > value.duration) {
      position = value.duration;
    } else if (position < const Duration()) {
      position = const Duration();
    }
    await _videoPlayerPlatform.seekTo(_textureId, position);
    _updatePosition(position);
  }

And if you what to stop it after stop time just use Future.delayed:

Future.delayed(Duration(milliseconds: 500), () {
  setState(() {
    _controller.pause();
  });
});

Upvotes: 1

Related Questions