seekTo method

Future<void> seekTo(
  1. Duration position
)

seek the current video position

Implementation

Future<void> seekTo(Duration position) async {
  if (position >= duration.value) {
    position = duration.value - const Duration(milliseconds: 100);
  }
  if (position < Duration.zero) {
    position = Duration.zero;
  }
  _position.value = position;
  customDebugPrint(
      "position in seek function is ${_position.value.toString()}");
  customDebugPrint(
      "duration in seek function is ${duration.value.toString()}");

  if (duration.value.inSeconds != 0) {
    await _videoPlayerController?.seek(position);

    // if (playerStatus.stopped) {
    //   play();
    // }
  } else {
    _timerForSeek?.cancel();
    _timerForSeek =
        Timer.periodic(const Duration(milliseconds: 200), (Timer t) async {
      //_timerForSeek = null;
      customDebugPrint("SEEK CALLED");
      if (duration.value.inSeconds != 0) {
        await _videoPlayerController?.seek(position);

        // if (playerStatus.stopped) {
        //   play();
        // }
        t.cancel();
        //_timerForSeek = null;
      }
    });
  }
}