mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-03-13 17:47:28 +08:00
feat: resume play time when changing source
This commit is contained in:
@@ -311,7 +311,13 @@ function PlayPageClient() {
|
|||||||
resumeTimeRef.current > 0
|
resumeTimeRef.current > 0
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
playerRef.current.currentTime = resumeTimeRef.current;
|
const duration = playerRef.current.duration || 0;
|
||||||
|
let target = resumeTimeRef.current;
|
||||||
|
// 如果目标时间距离结尾过近,为避免自动触发下一集,向前偏移 5 秒
|
||||||
|
if (duration && target >= duration - 2) {
|
||||||
|
target = Math.max(0, duration - 5);
|
||||||
|
}
|
||||||
|
playerRef.current.currentTime = target;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('恢复播放进度失败:', err);
|
console.warn('恢复播放进度失败:', err);
|
||||||
}
|
}
|
||||||
@@ -506,6 +512,9 @@ function PlayPageClient() {
|
|||||||
newTitle: string
|
newTitle: string
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
|
// 记录当前播放进度(仅在同一集数切换时恢复)
|
||||||
|
const currentPlayTime = playerRef.current?.currentTime || 0;
|
||||||
|
|
||||||
// 显示换源加载状态
|
// 显示换源加载状态
|
||||||
setSourceChanging(true);
|
setSourceChanging(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
@@ -536,6 +545,14 @@ function PlayPageClient() {
|
|||||||
targetIndex = 0;
|
targetIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果仍然是同一集数且播放进度有效,则在播放器就绪后恢复到原始进度
|
||||||
|
if (targetIndex === currentEpisodeIndex && currentPlayTime > 1) {
|
||||||
|
resumeTimeRef.current = currentPlayTime;
|
||||||
|
} else {
|
||||||
|
// 否则从头开始播放,防止影响后续选集逻辑
|
||||||
|
resumeTimeRef.current = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// 更新URL参数(不刷新页面)
|
// 更新URL参数(不刷新页面)
|
||||||
const newUrl = new URL(window.location.href);
|
const newUrl = new URL(window.location.href);
|
||||||
newUrl.searchParams.set('source', newSource);
|
newUrl.searchParams.set('source', newSource);
|
||||||
|
|||||||
Reference in New Issue
Block a user