From fa676c6c427275effd252446e8b9838b71479b76 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Sat, 13 Oct 2018 08:31:06 -0700 Subject: [PATCH] audio prefetch --- src/components/song-preview.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/song-preview.js b/src/components/song-preview.js index 6486dba..b956524 100644 --- a/src/components/song-preview.js +++ b/src/components/song-preview.js @@ -194,14 +194,20 @@ AFRAME.registerComponent('song-preview-system', { playSong: function (challengeId) { if (!challengeId) { return; } + + const audioanalyser = this.analyserEl.components.audioanalyser; this.audio = this.audioStore[challengeId]; this.audio.volume = 0; this.volumeTarget.volume = 0; - this.analyserEl.components.audioanalyser.resumeContext(); + audioanalyser.resumeContext(); this.audio.currentTime = this.audio.dataset.previewStartTime; this.audio.play(); this.fadeInAnimation.restart(); this.updateAnalyser(); + + // Prefetch buffer for playing. + if (audioanalyser.xhr) { audioanalyser.xhr.abort(); } + audioanalyser.fetchAudioBuffer(utils.getS3FileUrl(challengeId, 'song.ogg')); }, updateAnalyser: function () {