From c2585ea504ef3cea425210bd760324afa7906942 Mon Sep 17 00:00:00 2001 From: hehh Date: Fri, 28 Nov 2025 17:02:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(audio):=20=E4=BF=AE=E5=A4=8D=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=8A=A0=E8=BD=BD=E6=97=B6=E9=9F=B3=E9=A2=91=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=92=AD=E6=94=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除音频元素的 autoplay 属性 - 将音频播放逻辑移至 window load 事件后执行 - 添加播放失败的静默错误处理 - 保留循环播放和预加载设置 - 确保用户暂停状态在24小时内被记住 - 优化音频播放时机以提升用户体验 --- about.html | 2 +- js/about.js | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/about.html b/about.html index 8c8f07c..16b214d 100644 --- a/about.html +++ b/about.html @@ -296,7 +296,7 @@ - + diff --git a/js/about.js b/js/about.js index a9d75f3..84dad1f 100644 --- a/js/about.js +++ b/js/about.js @@ -1017,16 +1017,19 @@ class UIManager { this.audio = el; this.audio.loop = true; - // 检查是否在24小时内用户暂停过音乐 - const shouldRemainPaused = this.shouldMusicRemainPaused(); + // 页面加载完成后根据条件决定是否播放 + window.addEventListener('load', () => { + // 检查是否在24小时内用户暂停过音乐 + const shouldRemainPaused = this.shouldMusicRemainPaused(); - const tryPlay = () => { + // 如果不应该保持暂停状态,则尝试播放 if (!shouldRemainPaused) { this.audio.play().catch(() => { + // 静默处理播放失败 + console.error('Failed to play audio.'); }); } - }; - tryPlay(); + }); } updateCustomStyles(container, theme) { @@ -1042,4 +1045,4 @@ class UIManager { }); } -} \ No newline at end of file +}