From a2a366d34a2b125796ddaafbbba294996c657b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=82=A6?= Date: Tue, 13 Jan 2026 08:45:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=9F=B3=E9=A2=91=E6=92=AD=E6=94=BE):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DiOS=E8=AE=BE=E5=A4=87=E5=9C=A8=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E9=9A=90=E8=97=8F=E6=97=B6=E9=9F=B3=E9=A2=91=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E9=80=BB=E8=BE=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化音频播放逻辑,当页面隐藏时不再延迟播放。同时修正自动播放下一首时的立即播放条件判断。 --- index.html | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 135649c..c6a22db 100644 --- a/index.html +++ b/index.html @@ -967,6 +967,8 @@ const playAudioWithFallback = (audio, options = {}) => { if (!audio) return; const { deferOnIOS = false } = options; + const isHidden = typeof document !== 'undefined' && document.hidden; + const shouldDefer = deferOnIOS && IS_IOS && !isHidden; const doPlay = () => { const playPromise = audio.play(); if (playPromise && typeof playPromise.catch === 'function') { @@ -978,7 +980,7 @@ } }; - if (deferOnIOS && IS_IOS) { + if (shouldDefer) { const onCanPlay = () => { audio.removeEventListener('canplay', onCanPlay); doPlay(); @@ -1221,7 +1223,9 @@ const triggerAutoNext = () => { if (autoAdvanceLockRef.current) return; autoAdvanceLockRef.current = true; - playNext(true, { immediate: !IS_IOS, deferOnIOS: IS_IOS }); + const isHidden = typeof document !== 'undefined' && document.hidden; + const immediate = IS_IOS || isHidden; + playNext(true, { immediate, deferOnIOS: IS_IOS }); }; const isNearEnd = () => { @@ -1377,7 +1381,9 @@ } if (auto) { - autoNextPendingRef.current = true; + autoNextPendingRef.current = !options.immediate; + } else { + autoNextPendingRef.current = false; } let nextIdx;