diff --git a/lib/src/cupertino/cupertino_controls.dart b/lib/src/cupertino/cupertino_controls.dart index 7e16b38a1..6fd319e43 100644 --- a/lib/src/cupertino/cupertino_controls.dart +++ b/lib/src/cupertino/cupertino_controls.dart @@ -49,7 +49,7 @@ class _CupertinoControlsState extends State bool _subtitleOn = false; Timer? _bufferingDisplayTimer; bool _displayBufferingIndicator = false; - + double selectedSpeed = 1.0; late VideoPlayerController controller; // We know that _chewieController is set in didChangeDependencies @@ -559,6 +559,8 @@ class _CupertinoControlsState extends State if (chosenSpeed != null) { controller.setPlaybackSpeed(chosenSpeed); + + selectedSpeed = chosenSpeed; } if (_latestValue.isPlaying) { @@ -748,20 +750,30 @@ class _CupertinoControlsState extends State }); } - void _skipBack() { + Future _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 _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); + }); } void _startHideTimer() {