diff --git a/src/stores/player.ts b/src/stores/player.ts index 9d82fe1..e3e46e9 100644 --- a/src/stores/player.ts +++ b/src/stores/player.ts @@ -149,12 +149,16 @@ export const usePlayerStore = defineStore('player', () => { // --- Actions --- - const setPlaylist = async (list: any[], startIndex = 0) => { - playlist.value = list; - currentIndex.value = startIndex; - if (list.length > 0 && startIndex >= 0 && startIndex < list.length) { - await playSong(list[startIndex]); + const setPlaylist = async (list: Song[], startIndex = 0) => { + if (!Array.isArray(list) || list.length === 0) { + playlist.value = []; + currentIndex.value = -1; + return; } + const safeStart = Math.max(0, Math.min(startIndex, list.length - 1)); + playlist.value = list; + currentIndex.value = safeStart; + await playSong(list[safeStart]); }; const playFromList = async (song: Song, contextList: Song[]) => {