From fb35d42fc421a09d007b8547ca07ef8d8670494d Mon Sep 17 00:00:00 2001 From: alger Date: Tue, 4 Mar 2025 19:29:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E6=A8=A1=E5=BC=8F=20=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E4=B8=8B=E4=B8=80=E9=A6=96=E4=B8=8D=E6=98=AF=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/hooks/MusicListHook.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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]); };