Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[video_player] Don't restart when scrubbing to end #4488

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Comment on lines +787 to +788
Copy link
Member

@ditman ditman Nov 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at how this is handled in QT Player and it seems they also use the "looping" setting to determine what to do:

  • wasPlaying + scrolledToEnd + looping : jump and pause in FIRST frame of the video.
  • wasPlaying + scrolledToEnd + !looping : pause in last frame. This is the same as !wasPlaying + scrolledToEnd, regardless of value of looping.)

In all cases above, clicking "Play", immediately starts the video from the beginning.

In no case QT restarted when scrubbing to the end.

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