fix(player): 预热直出并与视频统一封面布局

This commit is contained in:
Zhou Weidong committed 2026-10-26 14:12:42 +08:00
1 parent a3a79f7068
commit 48b4e67d34
9 files changed
+119 -104

No files matched your search

@@ -6,7 +6,6 @@ import 'package:video_player/video_player.dart';
import '../../../core/theme/app_colors.dart';
const Duration _videoFadeDuration = Duration(milliseconds: 200);
const double _errorHorizontal = 32;
const int _errorMaxLines = 3;
@@ -20,6 +19,7 @@ class PlayerVideoSurface extends StatefulWidget {
this.handoff,
this.openingFrame,
this.holdOpeningUntilFirstFrame = false,
this.preparedFrameAvailable = false,
});
final VideoPlayerController? controller;
@@ -30,6 +30,9 @@ class PlayerVideoSurface extends StatefulWidget {
/// 播放中的新片源在位置首次前进前继续显示封面,避免混入未出帧纹理。
final bool holdOpeningUntilFirstFrame;
/// 相邻集预热槽已持有可用画面,进入页面时不需要封面兜底。
final bool preparedFrameAvailable;
final String videoUrl;
final bool theater;
@@ -69,15 +72,27 @@ class _PlayerVideoSurfaceState extends State<PlayerVideoSurface> {
Widget _frame(VideoPlayerValue? value) {
final controller = widget.controller;
final handoff = _liveHandoff(controller);
final firstFrameReady = _trackFrameState(controller, value);
final reveal = _shouldReveal(value, handoff != null) &&
final firstFrameSeen = _trackFrameState(controller, value);
final firstFrameReady =
widget.preparedFrameAvailable || firstFrameSeen;
final textureReady = _shouldReveal(value, handoff != null);
final reveal = textureReady &&
(!widget.holdOpeningUntilFirstFrame ||
widget.preparedFrameAvailable ||
firstFrameReady ||
_playbackStarted &&
value?.isPlaying == false &&
value?.isBuffering != true);
final showOpening =
widget.openingFrame != null && handoff == null && !reveal;
_logStateChange(value);
_logLayerState(value, handoff, reveal, firstFrameReady);
_logLayerState(
value,
handoff,
reveal,
firstFrameReady,
showOpening,
);
return Stack(
fit: StackFit.expand,
children: [
@@ -85,19 +100,15 @@ class _PlayerVideoSurfaceState extends State<PlayerVideoSurface> {
key: Key('player-fallback-background'),
color: AppColors.mediaBlack,
),
if (widget.openingFrame != null)
AnimatedOpacity(
if (showOpening)
KeyedSubtree(
key: const Key('player-opening-frame'),
opacity: reveal ? 0 : 1,
duration: handoff != null ? Duration.zero : _videoFadeDuration,
curve: Curves.easeOut,
child: widget.openingFrame!,
),
AnimatedOpacity(
key: const Key('player-video-opacity'),
opacity: reveal ? 1 : 0,
duration: handoff != null ? Duration.zero : _videoFadeDuration,
curve: Curves.easeOut,
duration: Duration.zero,
child: reveal && controller != null
? _VideoLayer(
controller: controller,
@@ -180,20 +191,24 @@ class _PlayerVideoSurfaceState extends State<PlayerVideoSurface> {
VideoPlayerController? handoff,
bool reveal,
bool firstFrameReady,
bool showOpening,
) {
if (!kDebugMode) return;
final reason = handoff != null
? 'handoff'
: !_shouldReveal(value, handoff != null)
? 'uninitialized'
: widget.preparedFrameAvailable
? 'warm-frame'
: !firstFrameReady && widget.holdOpeningUntilFirstFrame
? 'awaiting-first-frame'
: 'reveal';
final signature =
'opening=${widget.openingFrame == null ? 0 : reveal ? 0 : 1} '
'warm=${widget.preparedFrameAvailable ? 1 : 0} '
'frame=${firstFrameReady ? 1 : 0} '
'cover=${showOpening ? 1 : 0} '
'video=${reveal ? 1 : 0} handoff=${handoff == null ? 0 : 1} '
'init=${value?.isInitialized == true ? 1 : 0} '
'frame=${firstFrameReady ? 1 : 0} '
'playing=${value?.isPlaying == true ? 1 : 0} '
'buffering=${value?.isBuffering == true ? 1 : 0} '
'reason=$reason';