diff --git a/src/player/store.ts b/src/player/store.ts index 4a3e1e7..0da9866 100644 --- a/src/player/store.ts +++ b/src/player/store.ts @@ -1,4 +1,5 @@ import { Store, Module } from 'vuex' +import { trackListEquals } from '@/shared/utils' const audio = new Audio() const storedQueue = JSON.parse(localStorage.getItem('queue') || '[]') @@ -87,8 +88,10 @@ export const playerModule: Module = { }, actions: { - async playTrackList({ commit }, { queue, index }) { - commit('setQueue', [...queue]) + async playTrackList({ commit, state }, { tracks, index }) { + if (!trackListEquals(state.queue, tracks)) { + commit('setQueue', [...tracks]) + } commit('setQueueIndex', index) commit('setPlaying') await audio.play() diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 7f49032..cf4817d 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -1,4 +1,5 @@ import MD5 from 'md5-es' +import { Track } from '@/shared/api' export function randomString(): string { let arr = new Uint8Array(16) @@ -11,3 +12,15 @@ export function randomString(): string { export function md5(str: string): string { return MD5.hash(str) } + +export function trackListEquals(a: Track[], b: Track[]): boolean { + if (a.length !== b.length) { + return false + } + for (let i = 0; i < a.length; i++) { + if (a[i].id !== b[i].id) { + return false + } + } + return true +}