fix(player): 修正封面比例与首帧切换闪烁

This commit is contained in:
Zhou Weidong committed 2026-10-26 14:07:36 +08:00
1 parent 04f034817c
commit a3a79f7068
5 files changed
+148 -7

No files matched your search

@@ -5,6 +5,7 @@ import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/core/data/services/sprite_thumbnail_asset_loader.dart';
import 'package:fruitshorts/core/widgets/remote_image.dart';
import 'package:fruitshorts/pages/player/widgets/player_opening_frame.dart';
const String _spriteVtt = '''
@@ -82,6 +83,40 @@ void main() {
);
expect(find.byKey(const Key('player-opening-poster')), findsOneWidget);
expect(
find.byKey(const Key('player-opening-poster-backdrop')),
findsOneWidget,
);
});
testWidgets('should_constrain_poster_inside_native_vertical_frame', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(
home: PlayerOpeningFrame(
posterUrl: 'https://cdn.test/poster.jpg',
),
),
);
final stage = tester.widget<AspectRatio>(
find.byKey(const Key('player-opening-poster-stage')),
);
final poster = tester.widget<RemoteImage>(
find.byKey(const Key('player-opening-poster')),
);
final backdrop = tester.widget<RemoteImage>(
find.byKey(const Key('player-opening-poster-backdrop')),
);
expect(stage.aspectRatio, closeTo(3 / 4, 0.001));
expect(poster.fit, BoxFit.cover);
expect(backdrop.fit, BoxFit.cover);
expect(
find.byKey(const Key('player-opening-poster-blur')),
findsOneWidget,
);
});
testWidgets('should_reuse_decoded_sprite_when_parent_rebuilds', (
@@ -55,9 +55,23 @@ void main() {
final controller = await _pumpSurface(
tester,
openingFrame: const ColoredBox(color: Colors.red),
holdOpeningUntilFirstFrame: true,
);
expect(_opacity(tester), 0);
controller.value = const VideoPlayerValue(
duration: Duration(minutes: 1),
size: Size(1280, 720),
position: Duration.zero,
isInitialized: true,
isPlaying: true,
);
await tester.pump();
expect(_opacity(tester), 0);
expect(_openingOpacity(tester), 1);
expect(find.byKey(const Key('player-opening-frame')), findsOneWidget);
controller.value = const VideoPlayerValue(
duration: Duration(minutes: 1),
size: Size(1280, 720),
@@ -153,6 +167,7 @@ Future<VideoPlayerController> _pumpSurface(
WidgetTester tester, {
VideoPlayerValue? value,
Widget? openingFrame,
bool holdOpeningUntilFirstFrame = false,
}) async {
final controller = VideoPlayerController.networkUrl(
Uri.parse('http://192.168.31.187:8081/files/video.mp4'),
@@ -167,6 +182,7 @@ Future<VideoPlayerController> _pumpSurface(
videoUrl: controller.dataSource,
theater: false,
openingFrame: openingFrame,
holdOpeningUntilFirstFrame: holdOpeningUntilFirstFrame,
),
),
),