From 0fbed14ea7a359002a0fd070d218fca349c39fd9 Mon Sep 17 00:00:00 2001 From: ikmkj <1@qq,com> Date: Sat, 26 Jul 2025 01:20:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(music-player):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=9F=B3=E4=B9=90=E6=92=AD=E6=94=BE=E5=92=8C=E6=AD=8C=E8=AF=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -优化歌词解析逻辑,支持不同格式的歌词时间戳 - 修复设置当前音乐时的音频加载和播放问题 - 优化更新音乐 URL 的逻辑,确保平滑切换音源 - 修复了一些与音乐播放相关的潜在错误和不良行为 --- music-qianduan/src/components/MusicPlayer.vue | 12 ++-- music-qianduan/src/stores/player.js | 69 +++++++++++-------- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/music-qianduan/src/components/MusicPlayer.vue b/music-qianduan/src/components/MusicPlayer.vue index f8225f0..0656e4e 100644 --- a/music-qianduan/src/components/MusicPlayer.vue +++ b/music-qianduan/src/components/MusicPlayer.vue @@ -380,11 +380,13 @@ const loopModeText = computed(() => { // 解析歌词 const parsedLyric = computed(() => { - if (!currentMusic.value || !currentMusic.value.lyric) return []; + if (!currentMusic.value || typeof currentMusic.value.lyric !== 'string') { + return []; + } const lyric = currentMusic.value.lyric; const lines = lyric.split('\n'); const result = []; - const timeRegExp = /\[(\d{2}):(\d{2})\.(\d{2,3})\]/g; + const timeRegExp = /\[(\d{2}):(\d{2})\.(\d+)\]/g; for (const line of lines) { const text = line.replace(timeRegExp, '').trim(); @@ -394,8 +396,8 @@ const parsedLyric = computed(() => { while ((match = timeRegExp.exec(line)) !== null) { const min = parseInt(match, 10); const sec = parseInt(match, 10); - const ms = parseInt((match || '0').padEnd(3, '0'), 10); - const time = min * 60 + sec + ms / 1000; + const msStr = match; + const time = min * 60 + sec + parseFloat('0.' + msStr); result.push({ time, text }); } } @@ -574,7 +576,7 @@ watch(() => currentMusic.value?.id, (newId) => { lyricLines.value = {} if (isExpanded.value) expandedActiveTab.value = 'lyric' } -}, { immediate: true }) +})