Skip to content

Commit 74c4d5c

Browse files
committed
Added comments and optimised code
1 parent 7a25690 commit 74c4d5c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/src/cupertino/cupertino_controls.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,23 +750,27 @@ class _CupertinoControlsState extends State<CupertinoControls>
750750
});
751751
}
752752

753-
void _skipBack() {
753+
Future<void> _skipBack() async {
754754
_cancelAndRestartTimer();
755755
final beginning = Duration.zero.inMilliseconds;
756756
final skip =
757757
(_latestValue.position - const Duration(seconds: 15)).inMilliseconds;
758-
controller.seekTo(Duration(milliseconds: math.max(skip, beginning)));
758+
await controller.seekTo(Duration(milliseconds: math.max(skip, beginning)));
759+
// Restoring the video speed to selected speed
760+
// A delay of 1 second is added to ensure a smooth transition of speed after reversing the video as reversing is an asynchronous function
759761
Future.delayed(const Duration(milliseconds: 1000), () {
760762
controller.setPlaybackSpeed(selectedSpeed);
761763
});
762764
}
763765

764-
void _skipForward() {
766+
Future<void> _skipForward() async {
765767
_cancelAndRestartTimer();
766768
final end = _latestValue.duration.inMilliseconds;
767769
final skip =
768770
(_latestValue.position + const Duration(seconds: 15)).inMilliseconds;
769-
controller.seekTo(Duration(milliseconds: math.min(skip, end)));
771+
await controller.seekTo(Duration(milliseconds: math.min(skip, end)));
772+
// Restoring the video speed to selected speed
773+
// A delay of 1 second is added to ensure a smooth transition of speed after forwarding the video as forwaring is an asynchronous function
770774
Future.delayed(const Duration(milliseconds: 1000), () {
771775
controller.setPlaybackSpeed(selectedSpeed);
772776
});

0 commit comments

Comments
 (0)