Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
value = value.copyWith(isCompleted: true);
case VideoEventType.bufferingUpdate:
value = value.copyWith(buffered: event.buffered);
case VideoEventType.durationUpdate:
value = value.copyWith(duration: event.duration);
case VideoEventType.bufferingStart:
value = value.copyWith(isBuffering: true);
case VideoEventType.bufferingEnd:
Expand Down
21 changes: 21 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 @@ -1049,6 +1049,27 @@ void main() {
expect(controller.value.isBuffering, isFalse);
await tester.runAsync(controller.dispose);
});

testWidgets('buffering status', (WidgetTester tester) async {
final VideoPlayerController controller =
VideoPlayerController.networkUrl(_localhostUri);

await controller.initialize();
const Duration initDuration = Duration(milliseconds: 100);
controller.value = controller.value.copyWith(duration: initDuration);

final StreamController<VideoEvent> fakeVideoEventStream =
fakeVideoPlayerPlatform.streams[controller.playerId]!;

const Duration updatedDuration = Duration(milliseconds: 200);
fakeVideoEventStream.add(
VideoEvent(eventType: VideoEventType.durationUpdate, duration: updatedDuration),
);

await tester.pumpAndSettle();
expect(controller.value.duration, updatedDuration);
await tester.runAsync(controller.dispose);
});

Choose a reason for hiding this comment

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

medium

The test name 'buffering status' is misleading as this test verifies the duration update functionality. It's also a duplicate of another test name in this file, which can cause confusion. It should be renamed to be more descriptive. Additionally, an extra blank line can be removed for conciseness.

Suggested change
testWidgets('buffering status', (WidgetTester tester) async {
final VideoPlayerController controller =
VideoPlayerController.networkUrl(_localhostUri);
await controller.initialize();
const Duration initDuration = Duration(milliseconds: 100);
controller.value = controller.value.copyWith(duration: initDuration);
final StreamController<VideoEvent> fakeVideoEventStream =
fakeVideoPlayerPlatform.streams[controller.playerId]!;
const Duration updatedDuration = Duration(milliseconds: 200);
fakeVideoEventStream.add(
VideoEvent(eventType: VideoEventType.durationUpdate, duration: updatedDuration),
);
await tester.pumpAndSettle();
expect(controller.value.duration, updatedDuration);
await tester.runAsync(controller.dispose);
});
testWidgets('duration is updated by durationUpdate event', (WidgetTester tester) async {
final VideoPlayerController controller =
VideoPlayerController.networkUrl(_localhostUri);
await controller.initialize();
const Duration initDuration = Duration(milliseconds: 100);
controller.value = controller.value.copyWith(duration: initDuration);
final StreamController<VideoEvent> fakeVideoEventStream =
fakeVideoPlayerPlatform.streams[controller.playerId]!;
const Duration updatedDuration = Duration(milliseconds: 200);
fakeVideoEventStream.add(
VideoEvent(eventType: VideoEventType.durationUpdate, duration: updatedDuration),
);
await tester.pumpAndSettle();
expect(controller.value.duration, updatedDuration);
await tester.runAsync(controller.dispose);
});

});
});

Expand Down