seekTo method
seek the current video position
Implementation
Future<void> seekTo(Duration position) async {
_position.value = position;
print("duration in seek function is ${duration.value.toString()}");
if (duration.value.inSeconds != 0) {
if (position <= duration.value) {
if (windows) {
_videoPlayerControllerWindows?.seek(position);
} else {
await _videoPlayerController?.seekTo(position);
}
} else {
if (windows) {
_videoPlayerControllerWindows
?.seek(duration.value - Duration(milliseconds: 100));
} else {
await _videoPlayerController
?.seekTo(duration.value - Duration(milliseconds: 100));
}
}
if (playerStatus.stopped) {
play();
}
} else {
_timerForSeek?.cancel();
_timerForSeek =
Timer.periodic(Duration(milliseconds: 200), (Timer t) async {
//_timerForSeek = null;
print("SEEK CALLED");
if (duration.value.inSeconds != 0) {
if (position <= duration.value) {
if (windows) {
_videoPlayerControllerWindows?.seek(position);
} else {
await _videoPlayerController?.seekTo(position);
}
} else {
if (windows) {
_videoPlayerControllerWindows
?.seek(duration.value - Duration(milliseconds: 100));
} else {
await _videoPlayerController
?.seekTo(duration.value - Duration(milliseconds: 100));
}
}
if (playerStatus.stopped) {
play();
}
t.cancel();
_timerForSeek = null;
}
});
}
}