fix(player): 修正缓冲态与首帧时间闪现
This commit is contained in:
1 parent
0f27daf664
commit
350d16db75
8 files changed
+262
-22
No files matched your search
@@ -23,6 +23,7 @@ class _FeedProgressBar extends StatefulWidget {
|
||||
this.spriteAxisService,
|
||||
this.thumbnailsUrl,
|
||||
this.episodeId,
|
||||
this.suppressBufferLoading = false,
|
||||
this.onScrubStart,
|
||||
this.onScrubEnd,
|
||||
this.onSeek,
|
||||
@@ -37,6 +38,7 @@ class _FeedProgressBar extends StatefulWidget {
|
||||
final SpriteThumbnailAxisSource? spriteAxisService;
|
||||
final String? thumbnailsUrl;
|
||||
final String? episodeId;
|
||||
final bool suppressBufferLoading;
|
||||
final VoidCallback? onScrubStart;
|
||||
final VoidCallback? onScrubEnd;
|
||||
final ValueChanged<Duration>? onSeek;
|
||||
@@ -52,6 +54,7 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
Timer? _bufferTimer;
|
||||
bool _buffering = false;
|
||||
bool _dragging = false;
|
||||
Duration? _lastPosition;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -67,6 +70,7 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
_bufferTimer?.cancel();
|
||||
_bufferTimer = null;
|
||||
_buffering = false;
|
||||
_lastPosition = null;
|
||||
_attachSource();
|
||||
}
|
||||
if (oldWidget.cancelScrubRequest != widget.cancelScrubRequest) {
|
||||
@@ -77,6 +81,7 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
_bufferTimer?.cancel();
|
||||
_bufferTimer = null;
|
||||
_buffering = false;
|
||||
_lastPosition = null;
|
||||
if (widget.locked) {
|
||||
_dragging = false;
|
||||
_preview = null;
|
||||
@@ -84,6 +89,13 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
_syncBufferState(notify: false);
|
||||
}
|
||||
}
|
||||
if (oldWidget.suppressBufferLoading != widget.suppressBufferLoading) {
|
||||
_bufferTimer?.cancel();
|
||||
_bufferTimer = null;
|
||||
_buffering = false;
|
||||
_lastPosition = null;
|
||||
_syncBufferState(notify: false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -100,7 +112,11 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
final width = constraints.maxWidth;
|
||||
final source = widget.controller;
|
||||
final scrubbing = _dragging;
|
||||
final loading = !widget.locked && !scrubbing && _buffering;
|
||||
final loading =
|
||||
!widget.locked &&
|
||||
!widget.suppressBufferLoading &&
|
||||
!scrubbing &&
|
||||
_buffering;
|
||||
final track = widget.locked
|
||||
? _inactiveTrack()
|
||||
: source == null
|
||||
@@ -199,14 +215,24 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
|
||||
void _syncBufferState({bool notify = true}) {
|
||||
final source = widget.controller;
|
||||
if (widget.locked || source == null) {
|
||||
if (widget.locked || widget.suppressBufferLoading || source == null) {
|
||||
_bufferTimer?.cancel();
|
||||
_bufferTimer = null;
|
||||
_lastPosition = null;
|
||||
_setBuffering(false, notify: notify);
|
||||
return;
|
||||
}
|
||||
final value = source.value;
|
||||
if (!value.isInitialized) {
|
||||
_bufferTimer?.cancel();
|
||||
_bufferTimer = null;
|
||||
_lastPosition = null;
|
||||
_setBuffering(false, notify: notify);
|
||||
return;
|
||||
}
|
||||
final previousPosition = _lastPosition;
|
||||
_lastPosition = value.position;
|
||||
if (previousPosition != null && value.position > previousPosition) {
|
||||
_bufferTimer?.cancel();
|
||||
_bufferTimer = null;
|
||||
_setBuffering(false, notify: notify);
|
||||
@@ -218,14 +244,22 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
_setBuffering(false, notify: notify);
|
||||
return;
|
||||
}
|
||||
if (previousPosition == null &&
|
||||
value.isPlaying &&
|
||||
value.position > Duration.zero) {
|
||||
_setBuffering(false, notify: notify);
|
||||
return;
|
||||
}
|
||||
if (_buffering || _bufferTimer != null) return;
|
||||
final bufferingPosition = value.position;
|
||||
_bufferTimer = Timer(_bufferDebounce, () {
|
||||
_bufferTimer = null;
|
||||
final current = widget.controller;
|
||||
if (!mounted ||
|
||||
current != source ||
|
||||
!current!.value.isInitialized ||
|
||||
!current.value.isBuffering) {
|
||||
!current.value.isBuffering ||
|
||||
current.value.position != bufferingPosition) {
|
||||
return;
|
||||
}
|
||||
_setBuffering(true);
|
||||
|
||||
Reference in new issue
Block a user