diff --git a/src/core/player/PlayerController.ts b/src/core/player/PlayerController.ts index 7cc781560..6a001a682 100644 --- a/src/core/player/PlayerController.ts +++ b/src/core/player/PlayerController.ts @@ -211,7 +211,13 @@ class PlayerController { // 通知桌面歌词 if (isElectron) { window.electron.ipcRenderer.send("desktop-lyric:update-data", { + currentTime: startSeek, lyricLoading: true, + songId: song.id, + songOffset: statusStore.getSongOffset(song.id), + lrcData: [], + yrcData: [], + lyricIndex: -1, }); } // 更新任务栏歌词窗口的元数据 diff --git a/src/utils/initIpc.ts b/src/utils/initIpc.ts index 2ed95b6ee..8b3eb63f0 100644 --- a/src/utils/initIpc.ts +++ b/src/utils/initIpc.ts @@ -85,7 +85,7 @@ const initIpc = () => { ); // 给任务栏歌词初始数据 -window.electron.ipcRenderer.on(TASKBAR_IPC_CHANNELS.REQUEST_DATA, async () => { + window.electron.ipcRenderer.on(TASKBAR_IPC_CHANNELS.REQUEST_DATA, async () => { const musicStore = useMusicStore(); const statusStore = useStatusStore(); @@ -140,6 +140,9 @@ window.electron.ipcRenderer.on(TASKBAR_IPC_CHANNELS.REQUEST_DATA, async () => { const statusStore = useStatusStore(); if (player) { const { name, artist } = getPlayerInfoObj() || {}; + const songLyric = statusStore.lyricLoading + ? { lrcData: [], yrcData: [] } + : toRaw(musicStore.songLyric); window.electron.ipcRenderer.send( "desktop-lyric:update-data", cloneDeep({ @@ -149,8 +152,8 @@ window.electron.ipcRenderer.on(TASKBAR_IPC_CHANNELS.REQUEST_DATA, async () => { currentTime: statusStore.currentTime, songId: musicStore.playSong?.id, songOffset: statusStore.getSongOffset(musicStore.playSong?.id), - lrcData: musicStore.songLyric.lrcData ?? [], - yrcData: musicStore.songLyric.yrcData ?? [], + lrcData: songLyric.lrcData ?? [], + yrcData: songLyric.yrcData ?? [], lyricIndex: statusStore.lyricIndex, lyricLoading: statusStore.lyricLoading, }), diff --git a/src/views/DesktopLyric/index.vue b/src/views/DesktopLyric/index.vue index 77416cb65..bd523b46f 100644 --- a/src/views/DesktopLyric/index.vue +++ b/src/views/DesktopLyric/index.vue @@ -182,6 +182,15 @@ const lyricData = reactive({ lyricIndex: -1, }); +const hasLyricLines = (data: Pick) => + Boolean(data.lrcData?.length || data.yrcData?.length); + +const shouldIgnoreLoadingUpdate = (data: LyricData) => { + if (data.lyricLoading !== true) return false; + if (hasLyricLines(data) || !hasLyricLines(lyricData)) return false; + return data.songId === undefined || data.songId === lyricData.songId; +}; + // 锚点时间(毫秒)与锚点帧时间,用于插值推进 let baseMs = 0; let anchorTick = 0; @@ -306,7 +315,7 @@ const renderLyricLines = computed(() => { return placeholder("SPlayer Desktop Lyric"); } // 加载中 - if (lyricData.lyricLoading) return placeholder("歌词加载中..."); + if (lyricData.lyricLoading && !lyrics?.length) return placeholder("歌词加载中..."); // 纯音乐 if (!lyrics?.length) return placeholder("纯音乐,请欣赏"); // 获取当前歌词索引 @@ -708,6 +717,12 @@ onMounted(() => { window.electron.ipcRenderer.on( "desktop-lyric:update-data", (_event, data: LyricData & { sendTimestamp?: number }) => { + if (shouldIgnoreLoadingUpdate(data)) { + if (isInitializing.value) { + isInitializing.value = false; + } + return; + } Object.assign(lyricData, data); // 首次接收到歌词数据时,立即结束初始化状态 if (isInitializing.value) {