diff --git a/src/renderer/hooks/MusicListHook.ts b/src/renderer/hooks/MusicListHook.ts index e5ae3d6..ce9cf71 100644 --- a/src/renderer/hooks/MusicListHook.ts +++ b/src/renderer/hooks/MusicListHook.ts @@ -156,7 +156,20 @@ export const useMusicListHook = () => { state.play = true; return; } - const playListIndex = (state.playListIndex + 1) % state.playList.length; + + let playListIndex: number; + + if (state.playMode === 2) { + // 随机播放模式 + do { + playListIndex = Math.floor(Math.random() * state.playList.length); + } while (playListIndex === state.playListIndex && state.playList.length > 1); + } else { + // 列表循环模式 + playListIndex = (state.playListIndex + 1) % state.playList.length; + } + + state.playListIndex = playListIndex; await handlePlayMusic(state, state.playList[playListIndex]); };