feat(player): 增加进度条拖动画面预览
This commit is contained in:
1 parent
d06dce9753
commit
51c56d884b
15 files changed
+1493
-77
No files matched your search
@@ -17,6 +17,9 @@ class _FeedProgressBar extends StatefulWidget {
|
||||
required this.hitHeight,
|
||||
this.onScrubStart,
|
||||
this.onSeek,
|
||||
this.thumbnailService,
|
||||
required this.episodeId,
|
||||
required this.posterUrl,
|
||||
});
|
||||
|
||||
final ValueListenable<VideoPlayerValue>? controller;
|
||||
@@ -25,6 +28,9 @@ class _FeedProgressBar extends StatefulWidget {
|
||||
final double hitHeight;
|
||||
final VoidCallback? onScrubStart;
|
||||
final ValueChanged<Duration>? onSeek;
|
||||
final PlaybackThumbnailService? thumbnailService;
|
||||
final String episodeId;
|
||||
final String posterUrl;
|
||||
|
||||
@override
|
||||
State<_FeedProgressBar> createState() => _FeedProgressBarState();
|
||||
@@ -51,6 +57,7 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
_bufferTimer?.cancel();
|
||||
_bufferTimer = null;
|
||||
_buffering = false;
|
||||
widget.thumbnailService?.cancelPending();
|
||||
_attachSource();
|
||||
}
|
||||
if (oldWidget.locked != widget.locked) {
|
||||
@@ -58,6 +65,7 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
_bufferTimer = null;
|
||||
_buffering = false;
|
||||
if (widget.locked) {
|
||||
widget.thumbnailService?.cancelPending();
|
||||
_preview = null;
|
||||
} else {
|
||||
_syncBufferState(notify: false);
|
||||
@@ -69,6 +77,7 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
void dispose() {
|
||||
_detachSource(widget.controller);
|
||||
_bufferTimer?.cancel();
|
||||
if (_preview != null) widget.thumbnailService?.cancelPending();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -104,6 +113,14 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
!widget.locked &&
|
||||
!loading &&
|
||||
(source?.value.isInitialized ?? false);
|
||||
final video = source?.value;
|
||||
final previewPosition = _preview == null || video == null
|
||||
? null
|
||||
: seekPositionForFraction(_preview!, video.duration);
|
||||
final showPreview =
|
||||
previewPosition != null &&
|
||||
widget.thumbnailService != null &&
|
||||
widget.episodeId.isNotEmpty;
|
||||
return GestureDetector(
|
||||
key: const Key('home-feed-progress'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
@@ -117,10 +134,28 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
? (details) => _update(details.localPosition.dx / width)
|
||||
: null,
|
||||
onHorizontalDragEnd: interactive ? (_) => _commit(_preview) : null,
|
||||
onHorizontalDragCancel: interactive
|
||||
? () => setState(() => _preview = null)
|
||||
: null,
|
||||
child: track,
|
||||
onHorizontalDragCancel: interactive ? _cancelPreview : null,
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
track,
|
||||
if (showPreview)
|
||||
Positioned(
|
||||
left: scrubPreviewLeft(
|
||||
trackWidth: width,
|
||||
fraction: _preview!,
|
||||
),
|
||||
bottom: widget.hitHeight + 8,
|
||||
child: ScrubPreviewCard(
|
||||
service: widget.thumbnailService!,
|
||||
episodeId: widget.episodeId,
|
||||
posterUrl: widget.posterUrl,
|
||||
position: previewPosition,
|
||||
duration: video!.duration,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -230,6 +265,12 @@ class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
Duration(milliseconds: (total * fraction.clamp(0.0, 1.0)).round()),
|
||||
);
|
||||
}
|
||||
widget.thumbnailService?.cancelPending();
|
||||
setState(() => _preview = null);
|
||||
}
|
||||
|
||||
void _cancelPreview() {
|
||||
widget.thumbnailService?.cancelPending();
|
||||
setState(() => _preview = null);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user