Skip to content

一分钟搭建影视站,支持Docker等部署方式

Merge pull request #935 from wangyaoheng312/fix-history-resume-and-control-autohide

bestZweifd41d5a06661
diff --cc src/components/player-shell.tsx
index cae50a7,221d6de..3598a21
--- a/src/components/player-shell.tsx
+++ b/src/components/player-shell.tsx
@@@ -174,33 -204,9 +216,15 @@@ export function PlayerShell(
hls.loadSource(mediaUrl);
hls.attachMedia(video);
- hls.on(Hls.Events.MANIFEST_PARSED, async () => {
+ hls.on(Hls.Events.MANIFEST_PARSED, () => {
recoveryRef.current?.markHealthy();
+ // master playlist 的档位高度:多码率源在这里就能拿到上限
+ const heights = hls.levels
+ .map((level) => level.height)
+ .filter((h): h is number => typeof h === 'number' && h > 0);
+ if (heights.length > 0) reportQuality(Math.max(...heights));
- // 预取锚点:恢复进度时直接取恢复目标。赋值后 video.currentTime 未必立刻反映
- // (Safari 系),而 ensure 是以「锚点未变」为前提复用 parsing 中的运行的——
- // 这里读到旧值会把窗口建在片头,且白等一次纠错重建。
- let prefetchAnchor = video.currentTime;
- // 进度恢复(每集一次):优先 URL position,其次 IndexedDB 记录
- if (!restoredRef.current) {
- restoredRef.current = true;
- try {
- const saved = (await propsRef.current.getRestorePosition?.()) ?? 0;
- const duration = artRef.current?.duration || 0;
- if (saved > 10 && duration > 0 && saved < duration - 2) {
- if (artRef.current) artRef.current.currentTime = saved;
- prefetchAnchor = saved;
- showHint(`已从 ${formatTime(saved)} 继续播放`);
- }
- } catch { /* 忽略恢复失败 */ }
- }
- // 新集立即预取(否则要等 timeupdate 的 30s 节流,起播初期无缓存)
- ensurePrefetch(mediaUrl, prefetchAnchor);
- video.play().catch(() => {});
++ // 进度恢复改由 restoreAndStart 处理:duration 未就绪时不消费标记,挂事件重试
+ void restoreAndStart();
});
// 播放链路恢复(FRAG_LOADED / MANIFEST_PARSED):静默窗外清零连续失败计数
hls.on(Hls.Events.FRAG_LOADED, () => recoveryRef.current?.markHealthy());
@@@ -502,7 -506,12 +548,13 @@@
el?.removeEventListener('touchcancel', onTouchEnd);
el?.removeEventListener('touchmove', onTouchMove);
el?.removeEventListener('contextmenu', onContextMenu);
+ art.video?.removeEventListener('resize', reportVideoHeight);
+ el?.removeEventListener('mousemove', showControlsOnPointerMove);
+ el?.removeEventListener('mouseleave', hideControlsOnMouseLeave);
+ if (controlHideTimer) clearTimeout(controlHideTimer);
+ restoreCleanupRef.current?.();
+ restoreCleanupRef.current = null;
+ Artplayer.CONTROL_HIDE_TIME = previousControlHideTime;
hlsRef.current?.destroy();
hlsRef.current = null;
recoveryRef.current?.dispose();