Skip to content

Commit

Permalink
Added comments and optimised code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kronos-2701 committed Sep 18, 2023
1 parent 7a25690 commit 74c4d5c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -750,23 +750,27 @@ class _CupertinoControlsState extends State<CupertinoControls>
});
}

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

void _skipForward() {
Future<void> _skipForward() async {
_cancelAndRestartTimer();
final end = _latestValue.duration.inMilliseconds;
final skip =
(_latestValue.position + const Duration(seconds: 15)).inMilliseconds;
controller.seekTo(Duration(milliseconds: math.min(skip, end)));
await controller.seekTo(Duration(milliseconds: math.min(skip, end)));
// Restoring the video speed to selected speed
// A delay of 1 second is added to ensure a smooth transition of speed after forwarding the video as forwaring is an asynchronous function
Future.delayed(const Duration(milliseconds: 1000), () {
controller.setPlaybackSpeed(selectedSpeed);
});
Expand Down

0 comments on commit 74c4d5c

Please sign in to comment.