Skip to content

Commit

Permalink
Merge pull request fluttercommunity#774 from Kronos-2701/master
Browse files Browse the repository at this point in the history
Fixed : Playback speed reset on forwarding video
  • Loading branch information
diegotori authored Nov 28, 2023
2 parents 2a1dd99 + 74c4d5c commit ad28f5d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class _CupertinoControlsState extends State<CupertinoControls>
bool _subtitleOn = false;
Timer? _bufferingDisplayTimer;
bool _displayBufferingIndicator = false;

double selectedSpeed = 1.0;
late VideoPlayerController controller;

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

if (chosenSpeed != null) {
controller.setPlaybackSpeed(chosenSpeed);

selectedSpeed = chosenSpeed;
}

if (_latestValue.isPlaying) {
Expand Down Expand Up @@ -748,20 +750,30 @@ 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);
});
}

void _startHideTimer() {
Expand Down

0 comments on commit ad28f5d

Please sign in to comment.