Merge pull request #72 from algerkong/fix/random-music

fix: 修复随机播放模式 手动下一首不是随机的问题
This commit is contained in:
Alger
2025-03-04 19:32:29 +08:00
committed by GitHub
+14 -1
View File
@@ -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]);
};