seekTo method
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.
Implementation
Future<void> seekTo(Duration? position) async {
_timer?.cancel();
bool isPlaying = value.isPlaying;
final int positionInMs = value.position.inMilliseconds;
final int durationInMs = value.duration?.inMilliseconds ?? 0;
if (positionInMs >= durationInMs && position?.inMilliseconds == 0) {
isPlaying = true;
}
if (_isDisposed) {
return;
}
Duration? positionToSeek = position;
if (position! > value.duration!) {
positionToSeek = value.duration;
} else if (position < const Duration()) {
positionToSeek = const Duration();
}
_seekPosition = positionToSeek;
await _videoPlayerPlatform.seekTo(_textureId, positionToSeek);
_updatePosition(position);
if (isPlaying) {
play();
} else {
pause();
}
}