From 323878e4e669459c239a715a76e4eb378f541409 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Mon, 23 Jul 2018 14:11:51 +0200 Subject: [PATCH] no need to prioriiize if already loading --- src/components/song-preview.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/song-preview.js b/src/components/song-preview.js index 84dfdcc..21744e7 100644 --- a/src/components/song-preview.js +++ b/src/components/song-preview.js @@ -41,14 +41,15 @@ AFRAME.registerComponent('song-preview-system', { if (data.selectedChallengeId && oldData.selectedChallengeId !== data.selectedChallengeId) { - if (!this.preloadedAudioIds.includes(data.selectedChallengeId)) { + if (!this.preloadedAudioIds.includes(data.selectedChallengeId) && + data.selectedChallengeId !== this.currentLoadingId) { // If not yet preloaded, pause the preload queue until this song is loaded. console.log(`[song-preview] Prioritizing loading of ${data.selectedChallengeId}`); - this.loadingChallengeId = data.selectedChallengeId; + this.priorityLoadingChallengeId = data.selectedChallengeId; this.audioStore[data.selectedChallengeId].addEventListener('loadeddata', () => { console.log(`[song-preview] Finished load of priority ${data.selectedChallengeId}`); this.preloadedAudioIds.push(data.selectedChallengeId); - this.loadingChallengeId = ''; + this.priorityLoadingChallengeId = ''; // Resume preloading queue. if (preloadQueue.length) { console.log(`[song-preview] Resuming queue with ${preloadQueue[0].challengeId}`); @@ -107,7 +108,7 @@ AFRAME.registerComponent('song-preview-system', { this.preloadedAudioIds.push(preloadItem.challengeId); this.currentLoadingId = ''; console.log(`[song-preview] ${this.preloadQueue.length} in queue`); - if (this.preloadQueue.length && !this.loadingChallengeId) { + if (this.preloadQueue.length && !this.priorityLoadingChallengeId) { this.preloadMetadata(this.preloadQueue.shift()); } });