Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 2 additions & 1 deletion packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 2.9.3

* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
* Added `setVideoPositionUpdatesInterval` to allow setting position updates periodic intervals

## 2.9.2

Expand Down
3 changes: 1 addition & 2 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,9 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
if (value.isPlaying) {
await _videoPlayerPlatform.play(_textureId);

// Cancel previous timer.
_timer?.cancel();
_timer = Timer.periodic(
const Duration(milliseconds: 500),
const Duration(milliseconds: 100),
(Timer timer) async {
if (_isDisposed) {
return;
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/packages/tree/main/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.9.2
version: 2.9.3

environment:
sdk: ^3.4.0
Expand Down
35 changes: 35 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 @@ -956,6 +956,41 @@ void main() {
});
});
});
test('updates position', () async {
final VideoPlayerController controller = VideoPlayerController.networkUrl(
_localhostUri,
videoPlayerOptions: VideoPlayerOptions(),
);

await controller.initialize();

// Set a custom interval
const Duration customInterval = Duration(milliseconds: 100);

final List<Duration> positions = <Duration>[];
final Completer<void> intervalUpdateCompleter = Completer<void>();

// Listen for position updates
controller.addListener(() {
positions.add(controller.value.position);
if (positions.length >= 3 && !intervalUpdateCompleter.isCompleted) {
intervalUpdateCompleter.complete();
}
});
await controller.play();
for (int i = 0; i < 3; i++) {
await Future<void>.delayed(customInterval);
fakeVideoPlayerPlatform._positions[controller.textureId] =
Duration(milliseconds: i * customInterval.inMilliseconds);
}

// Wait for at least 3 position updates
await intervalUpdateCompleter.future.timeout(const Duration(seconds: 5));

// Verify that the intervals between updates are approximately correct
expect(positions[1] - positions[0], greaterThanOrEqualTo(customInterval));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't this test as written pass without the rest of the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just tested using 500 ms for the updates and it failed, but i will add another test related to the captions since its the more related to this pr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the other test and I hope its shows the problem more, let me know if there anything else I can fix.

Thank you.

expect(positions[2] - positions[1], greaterThanOrEqualTo(customInterval));
});

group('DurationRange', () {
test('uses given values', () {
Expand Down
Loading