Skip to content

Commit

Permalink
[video_player] Don't restart when scrubbing to end (flutter#4488)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmorgan committed Nov 9, 2021
1 parent 688ab6f commit b224f2f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.2.7

* Fixes a regression where dragging a [VideoProgressIndicator] while playing
would restart playback from the start of the video.

## 2.2.6

* Initialize player when size and duration become available on iOS
Expand Down
3 changes: 2 additions & 1 deletion packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,8 @@ class _VideoScrubberState extends State<_VideoScrubber> {
seekToRelativePosition(details.globalPosition);
},
onHorizontalDragEnd: (DragEndDetails details) {
if (_controllerWasPlaying) {
if (_controllerWasPlaying &&
controller.value.position != controller.value.duration) {
controller.play();
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
widgets on Android, iOS, and web.
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.2.6
version: 2.2.7

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
54 changes: 54 additions & 0 deletions packages/video_player/video_player/test/video_player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,60 @@ void main() {
});
});

group('scrubbing', () {
testWidgets('restarts on release if already playing',
(WidgetTester tester) async {
final VideoPlayerController controller = VideoPlayerController.network(
'https://127.0.0.1',
);
await controller.initialize();
final progressWidget =
VideoProgressIndicator(controller, allowScrubbing: true);

await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: progressWidget,
));

await controller.play();
expect(controller.value.isPlaying, isTrue);

final Rect progressRect = tester.getRect(find.byWidget(progressWidget));
await tester.dragFrom(progressRect.center, Offset(1.0, 0.0));
await tester.pumpAndSettle();

expect(controller.value.position, lessThan(controller.value.duration));
expect(controller.value.isPlaying, isTrue);

await controller.pause();
});

testWidgets('does not restart when dragging to end',
(WidgetTester tester) async {
final VideoPlayerController controller = VideoPlayerController.network(
'https://127.0.0.1',
);
await controller.initialize();
final progressWidget =
VideoProgressIndicator(controller, allowScrubbing: true);

await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: progressWidget,
));

await controller.play();
expect(controller.value.isPlaying, isTrue);

final Rect progressRect = tester.getRect(find.byWidget(progressWidget));
await tester.dragFrom(progressRect.center, progressRect.centerRight);
await tester.pumpAndSettle();

expect(controller.value.position, controller.value.duration);
expect(controller.value.isPlaying, isFalse);
});
});

group('caption', () {
test('works when seeking', () async {
final VideoPlayerController controller = VideoPlayerController.network(
Expand Down

0 comments on commit b224f2f

Please sign in to comment.