fix(player): 修正缓冲态与首帧时间闪现

This commit is contained in:
Zhou Weidong committed 2026-10-26 21:13:55 +08:00
1 parent 0f27daf664
commit 350d16db75
8 files changed
+262 -22

No files matched your search

+10
View File
@@ -855,6 +855,16 @@ void main() {
await tester.pump();
await gesture.up();
await tester.pumpAndSettle();
controller.value = const VideoPlayerValue(
duration: Duration(seconds: 100),
position: Duration(seconds: 40),
isInitialized: true,
isBuffering: true,
);
await tester.pump(const Duration(milliseconds: 400));
expect(find.byKey(const Key('home-feed-progress-thumb')), findsOneWidget);
expect(find.byKey(const Key('progress-loading')), findsNothing);
});
testWidgets('should_show_refresh_spinner_until_refresh_finishes', (
+118
View File
@@ -54,6 +54,11 @@ void main() {
expect(find.byKey(const Key('progress-loading')), findsNothing);
expect(find.byKey(const Key('progress-inactive')), findsOneWidget);
expect(find.byType(Slider), findsNothing);
expect(
find.byKey(const Key('player-progress-uninitialized-time')),
findsNothing,
);
expect(find.textContaining('00:00'), findsNothing);
});
testWidgets('should_show_inactive_track_and_disable_seek_when_locked', (
@@ -144,6 +149,119 @@ void main() {
expect(find.byType(Slider), findsOneWidget);
});
testWidgets(
'should_hide_buffering_loading_immediately_when_position_advances',
(tester) async {
final video = ValueNotifier<VideoPlayerValue>(
const VideoPlayerValue(
duration: Duration(seconds: 12),
position: Duration(seconds: 3),
isInitialized: true,
isPlaying: true,
isBuffering: true,
),
);
addTearDown(video.dispose);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SeekProgressBar(
valueListenable: video,
semanticsLabel: 'Seek video',
onSeek: (_) async {},
),
),
),
);
expect(find.byKey(const Key('progress-loading')), findsNothing);
await tester.pump(const Duration(milliseconds: 200));
video.value = const VideoPlayerValue(
duration: Duration(seconds: 12),
position: Duration(seconds: 4),
isInitialized: true,
isBuffering: true,
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(find.byKey(const Key('progress-loading')), findsNothing);
expect(find.byType(Slider), findsOneWidget);
video.value = const VideoPlayerValue(
duration: Duration(seconds: 12),
position: Duration(seconds: 4),
isInitialized: true,
isPlaying: true,
isBuffering: true,
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(find.byKey(const Key('progress-loading')), findsOneWidget);
expect(find.byType(Slider), findsNothing);
},
);
testWidgets('should_not_show_loading_for_prewarmed_episode', (tester) async {
final video = ValueNotifier<VideoPlayerValue>(
const VideoPlayerValue(
duration: Duration(seconds: 12),
position: Duration(seconds: 5),
isInitialized: true,
isPlaying: true,
isBuffering: true,
),
);
addTearDown(video.dispose);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SeekProgressBar(
valueListenable: video,
semanticsLabel: 'Seek video',
onSeek: (_) async {},
),
),
),
);
await tester.pump(const Duration(milliseconds: 400));
expect(find.byKey(const Key('progress-loading')), findsNothing);
expect(find.byType(Slider), findsOneWidget);
});
testWidgets(
'should_suppress_progress_loading_while_entry_loading_is_visible',
(tester) async {
final video = ValueNotifier<VideoPlayerValue>(
const VideoPlayerValue(
duration: Duration(seconds: 12),
position: Duration.zero,
isInitialized: true,
isBuffering: true,
),
);
addTearDown(video.dispose);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SeekProgressBar(
valueListenable: video,
semanticsLabel: 'Seek video',
suppressBufferLoading: true,
onSeek: (_) async {},
),
),
),
);
await tester.pump(const Duration(milliseconds: 400));
expect(find.byKey(const Key('progress-loading')), findsNothing);
expect(find.byType(Slider), findsOneWidget);
},
);
testWidgets('should_keep_slider_while_scrubbing_during_buffering', (
tester,
) async {
+48 -1
View File
@@ -361,7 +361,11 @@ void main() {
findsOneWidget,
);
expect(find.byKey(const Key('player-progress')), findsOneWidget);
expect(find.text('00:00 / 01:00'), findsOneWidget);
expect(
find.byKey(const Key('player-progress-uninitialized-time')),
findsNothing,
);
expect(find.text('00:00 / 01:00'), findsNothing);
// IgnorePointer 让加载中的播放暂停与上下滑穿透,滑动会关闭入口 loading。
expect(fullLogic.session.userWantsPlay, isTrue);
@@ -515,6 +519,49 @@ void main() {
expect(find.byKey(const Key('progress-inactive')), findsOneWidget);
});
testWidgets('should_only_show_progress_buffer_after_video_first_frame', (
tester,
) async {
final factory = _RouteVideoFactory();
await _pumpApp(tester, playerFactory: factory.create);
await _openSeriesPlayer(tester);
final videoIndex = factory.episodes.lastIndexWhere(
(episode) => episode.id == 'city-lights-demo-1',
);
final video = factory.created[videoIndex];
expect(video.controller.value.isInitialized, isTrue);
expect(find.byKey(const Key('player-entry-loading-overlay')), findsNothing);
video.controller.value = const VideoPlayerValue(
duration: Duration(minutes: 1),
size: Size(1280, 720),
position: Duration(seconds: 5),
isInitialized: true,
isPlaying: true,
isBuffering: true,
);
await tester.pump(const Duration(milliseconds: 400));
expect(find.byKey(const Key('progress-loading')), findsOneWidget);
expect(find.byKey(const Key('player-entry-loading-overlay')), findsNothing);
expect(find.byKey(const Key('player-video-loading')), findsNothing);
expect(find.byKey(const Key('player-ticket-loading')), findsNothing);
video.controller.value = const VideoPlayerValue(
duration: Duration(minutes: 1),
size: Size(1280, 720),
position: Duration(seconds: 6),
isInitialized: true,
isPlaying: true,
isBuffering: true,
);
await tester.pump();
expect(find.byKey(const Key('progress-loading')), findsNothing);
expect(find.byType(Slider), findsOneWidget);
});
testWidgets('should_pause_feed_when_auth_page_is_pushed_and_resume_on_pop', (
tester,
) async {