播放记录保存去重
This commit is contained in:
@@ -1773,6 +1773,7 @@ function PlayPageClient() {
|
|||||||
// 播放进度保存相关
|
// 播放进度保存相关
|
||||||
const saveIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
const saveIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
const lastSaveTimeRef = useRef<number>(0);
|
const lastSaveTimeRef = useRef<number>(0);
|
||||||
|
const lastSavedPlayTimeRef = useRef<number | null>(null);
|
||||||
|
|
||||||
// 下集预缓存相关
|
// 下集预缓存相关
|
||||||
const nextEpisodePreCacheTriggeredRef = useRef<boolean>(false);
|
const nextEpisodePreCacheTriggeredRef = useRef<boolean>(false);
|
||||||
@@ -5703,12 +5704,17 @@ function PlayPageClient() {
|
|||||||
const player = artPlayerRef.current;
|
const player = artPlayerRef.current;
|
||||||
const currentTime = player.currentTime || 0;
|
const currentTime = player.currentTime || 0;
|
||||||
const duration = player.duration || 0;
|
const duration = player.duration || 0;
|
||||||
|
const playTime = Math.floor(currentTime);
|
||||||
|
|
||||||
// 如果播放时间太短(少于5秒)或者视频时长无效,不保存
|
// 如果播放时间太短(少于5秒)或者视频时长无效,不保存
|
||||||
if (currentTime < 1 || !duration) {
|
if (currentTime < 1 || !duration) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lastSavedPlayTimeRef.current === playTime) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
saveLocalEpisodeProgress(
|
saveLocalEpisodeProgress(
|
||||||
episodeProgressContentKey,
|
episodeProgressContentKey,
|
||||||
@@ -5724,12 +5730,13 @@ function PlayPageClient() {
|
|||||||
cover: detailRef.current?.poster || '',
|
cover: detailRef.current?.poster || '',
|
||||||
index: currentEpisodeIndexRef.current + 1, // 转换为1基索引
|
index: currentEpisodeIndexRef.current + 1, // 转换为1基索引
|
||||||
total_episodes: detailRef.current?.episodes.length || 1,
|
total_episodes: detailRef.current?.episodes.length || 1,
|
||||||
play_time: Math.floor(currentTime),
|
play_time: playTime,
|
||||||
total_time: Math.floor(duration),
|
total_time: Math.floor(duration),
|
||||||
save_time: Date.now(),
|
save_time: Date.now(),
|
||||||
search_title: searchTitle,
|
search_title: searchTitle,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
lastSavedPlayTimeRef.current = playTime;
|
||||||
lastSaveTimeRef.current = Date.now();
|
lastSaveTimeRef.current = Date.now();
|
||||||
console.log('播放进度已保存:', {
|
console.log('播放进度已保存:', {
|
||||||
title: videoTitleRef.current,
|
title: videoTitleRef.current,
|
||||||
|
|||||||
Reference in New Issue
Block a user