mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-23 23:57:22 +08:00
fix: 修复播放并发控制死代码、shallowRef响应式、歌词IPC高频调用 (H-005/H-006/H-009)
- H-005: 删除 playerCore.ts 中无效的 playInProgress 局部变量 - H-006: fetchSongs 修改 shallowRef 元素后添加 triggerRef 触发更新 - H-009: sendLyricToWin 从每秒20次全量发送改为每秒5次轻量更新
This commit is contained in:
@@ -402,6 +402,7 @@ const setupAudioListeners = () => {
|
|||||||
let interval: any = null;
|
let interval: any = null;
|
||||||
// 播放状态恢复定时器:当 interval 因异常被清除时,自动恢复
|
// 播放状态恢复定时器:当 interval 因异常被清除时,自动恢复
|
||||||
let recoveryTimer: any = null;
|
let recoveryTimer: any = null;
|
||||||
|
let lyricThrottleCounter = 0;
|
||||||
|
|
||||||
const clearInterval = () => {
|
const clearInterval = () => {
|
||||||
if (interval) {
|
if (interval) {
|
||||||
@@ -457,8 +458,21 @@ const setupAudioListeners = () => {
|
|||||||
sendLyricToWin();
|
sendLyricToWin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isElectron && isLyricWindowOpen.value) {
|
// 节流发送轻量歌词进度更新(每 ~200ms / 约每 4 个 tick)
|
||||||
sendLyricToWin();
|
lyricThrottleCounter++;
|
||||||
|
if (isElectron && isLyricWindowOpen.value && lyricThrottleCounter % 4 === 0) {
|
||||||
|
try {
|
||||||
|
window.api.sendLyric(
|
||||||
|
JSON.stringify({
|
||||||
|
type: 'update',
|
||||||
|
nowIndex: nowIndex.value,
|
||||||
|
nowTime: nowTime.value,
|
||||||
|
isPlay: getPlayerStore().play
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
// 忽略发送失败
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('进度更新 interval 出错:', error);
|
console.error('进度更新 interval 出错:', error);
|
||||||
|
|||||||
@@ -335,17 +335,8 @@ export const usePlayerCoreStore = defineStore(
|
|||||||
console.warn('预加载触发失败(可能是依赖未加载或循环依赖),已忽略:', e);
|
console.warn('预加载触发失败(可能是依赖未加载或循环依赖),已忽略:', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
let playInProgress = false;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (playInProgress) {
|
|
||||||
console.warn('播放操作正在进行中,避免重复调用');
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
playInProgress = true;
|
|
||||||
const result = await playAudio(requestId);
|
const result = await playAudio(requestId);
|
||||||
playInProgress = false;
|
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
playbackRequestManager.completeRequest(requestId);
|
playbackRequestManager.completeRequest(requestId);
|
||||||
@@ -356,7 +347,6 @@ export const usePlayerCoreStore = defineStore(
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('自动播放音频失败:', error);
|
console.error('自动播放音频失败:', error);
|
||||||
playInProgress = false;
|
|
||||||
playbackRequestManager.failRequest(requestId);
|
playbackRequestManager.failRequest(requestId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useThrottleFn } from '@vueuse/core';
|
import { useThrottleFn } from '@vueuse/core';
|
||||||
import { createDiscreteApi } from 'naive-ui';
|
import { createDiscreteApi } from 'naive-ui';
|
||||||
import { defineStore, storeToRefs } from 'pinia';
|
import { defineStore, storeToRefs } from 'pinia';
|
||||||
import { computed, ref, shallowRef } from 'vue';
|
import { computed, ref, shallowRef, triggerRef } from 'vue';
|
||||||
|
|
||||||
import i18n from '@/../i18n/renderer';
|
import i18n from '@/../i18n/renderer';
|
||||||
import { useSongDetail } from '@/hooks/usePlayerHooks';
|
import { useSongDetail } from '@/hooks/usePlayerHooks';
|
||||||
@@ -83,6 +83,8 @@ export const usePlaylistStore = defineStore(
|
|||||||
playList.value[startIndex + index] = song;
|
playList.value[startIndex + index] = song;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 触发 shallowRef 响应式更新(直接修改元素不会自动触发)
|
||||||
|
triggerRef(playList);
|
||||||
|
|
||||||
// 预加载下一首歌曲的音频和封面
|
// 预加载下一首歌曲的音频和封面
|
||||||
if (nextSong) {
|
if (nextSong) {
|
||||||
|
|||||||
Reference in New Issue
Block a user