Skip to content

Commit ad28f5d

Browse files
authored
Merge pull request #774 from Kronos-2701/master
Fixed : Playback speed reset on forwarding video
2 parents 2a1dd99 + 74c4d5c commit ad28f5d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/src/cupertino/cupertino_controls.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class _CupertinoControlsState extends State<CupertinoControls>
4949
bool _subtitleOn = false;
5050
Timer? _bufferingDisplayTimer;
5151
bool _displayBufferingIndicator = false;
52-
52+
double selectedSpeed = 1.0;
5353
late VideoPlayerController controller;
5454

5555
// We know that _chewieController is set in didChangeDependencies
@@ -559,6 +559,8 @@ class _CupertinoControlsState extends State<CupertinoControls>
559559

560560
if (chosenSpeed != null) {
561561
controller.setPlaybackSpeed(chosenSpeed);
562+
563+
selectedSpeed = chosenSpeed;
562564
}
563565

564566
if (_latestValue.isPlaying) {
@@ -748,20 +750,30 @@ class _CupertinoControlsState extends State<CupertinoControls>
748750
});
749751
}
750752

751-
void _skipBack() {
753+
Future<void> _skipBack() async {
752754
_cancelAndRestartTimer();
753755
final beginning = Duration.zero.inMilliseconds;
754756
final skip =
755757
(_latestValue.position - const Duration(seconds: 15)).inMilliseconds;
756-
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
761+
Future.delayed(const Duration(milliseconds: 1000), () {
762+
controller.setPlaybackSpeed(selectedSpeed);
763+
});
757764
}
758765

759-
void _skipForward() {
766+
Future<void> _skipForward() async {
760767
_cancelAndRestartTimer();
761768
final end = _latestValue.duration.inMilliseconds;
762769
final skip =
763770
(_latestValue.position + const Duration(seconds: 15)).inMilliseconds;
764-
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
774+
Future.delayed(const Duration(milliseconds: 1000), () {
775+
controller.setPlaybackSpeed(selectedSpeed);
776+
});
765777
}
766778

767779
void _startHideTimer() {

0 commit comments

Comments
 (0)