From c9fac4b7fe8d8ae3b4e9a2fbfd8abe9ce27273d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=82=A6?= Date: Tue, 13 Jan 2026 17:47:46 +0800 Subject: [PATCH] =?UTF-8?q?=20=201.=20iOS=E8=87=AA=E5=8A=A8=E5=88=87?= =?UTF-8?q?=E6=AD=8C=E9=97=AE=E9=A2=98=EF=BC=882=E5=A4=84=EF=BC=89?= =?UTF-8?q?=EF=BC=9A=20=20=20=20=20-=20isNearEnd=EF=BC=9A=E9=98=88?= =?UTF-8?q?=E5=80=BC=200.15s=20=E2=86=92=200.5s=20=20=20=20=20-=20updateTi?= =?UTF-8?q?me=EF=BC=9A=E7=A7=BB=E9=99=A4=20iOS=20=E9=99=90=E5=88=B6=20=20?= =?UTF-8?q?=202.=20=E6=97=B6=E9=95=BF=E6=98=BE=E7=A4=BA=E8=B4=9F=E5=80=BC?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=882=E5=A4=84=EF=BC=89=EF=BC=9A=20=20?= =?UTF-8?q?=20=20=20-=20formatTime=EF=BC=9A=E5=A2=9E=E5=8A=A0=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=80=BC=E4=BF=9D=E6=8A=A4=20=20=20=20=20-=20resolveD?= =?UTF-8?q?urationSeconds=EF=BC=9A=E9=98=B2=E6=AD=A2=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E8=B4=9F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index c6a22db..ef20928 100644 --- a/index.html +++ b/index.html @@ -159,7 +159,8 @@ // --- Utility Functions --- const formatTime = (seconds) => { - if (!seconds) return "0:00"; + // 增加保护:处理负数、Infinity、NaN等异常值 + if (!Number.isFinite(seconds) || seconds < 0) return "0:00"; const mins = Math.floor(seconds / 60); const secs = Math.floor(seconds % 60); return `${mins}:${secs < 10 ? '0' : ''}${secs}`; @@ -232,11 +233,14 @@ if (audio.seekable && audio.seekable.length) { try { const end = audio.seekable.end(audio.seekable.length - 1); + // 增加负数检查:iOS锁屏时可能返回负数 if (Number.isFinite(end) && end > 0) return end; } catch (e) {} } } - return getSongDurationSeconds(song); + const fallbackDuration = getSongDurationSeconds(song); + // 再次确保不会返回负数或异常值 + return Number.isFinite(fallbackDuration) && fallbackDuration > 0 ? fallbackDuration : 0; }; // --- ID Normalization --- @@ -1231,14 +1235,16 @@ const isNearEnd = () => { const durationSeconds = resolveDurationSeconds(audio, currentSongRef.current); if (!Number.isFinite(durationSeconds) || durationSeconds <= 0) return false; - const threshold = IS_IOS ? 0.15 : 0.35; + // iOS锁屏时timeupdate频率降低,需要更大的提前量 + const threshold = IS_IOS ? 0.5 : 0.35; return audio.currentTime >= durationSeconds - threshold; }; const updateTime = () => { setCurrentTime(audio.currentTime); if (autoAdvanceLockRef.current) return; - if (!IS_IOS && isNearEnd()) triggerAutoNext(); + // 移除iOS限制:所有平台都使用timeupdate检查,解决iOS锁屏时ended事件不触发的问题 + if (isNearEnd()) triggerAutoNext(); }; const updateDuration = () => setDuration(resolveDurationSeconds(audio, currentSongRef.current)); const onEnded = () => triggerAutoNext();