From 308df53ea01f16fb3abd4fb8178c0efcf2a1d141 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Fri, 26 Oct 2018 12:28:54 -0700 Subject: [PATCH] fix inaccurate current time in preload --- src/components/beat-loader.js | 5 ++--- src/components/song.js | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/beat-loader.js b/src/components/beat-loader.js index a460fa5..9cf864a 100644 --- a/src/components/beat-loader.js +++ b/src/components/beat-loader.js @@ -140,7 +140,7 @@ AFRAME.registerComponent('beat-loader', { // Re-sync song with beats playback. const songComponent = this.el.components.song; - const currentTime = songComponent.context.currentTime - songComponent.songStartTime; + const currentTime = songComponent.getCurrentTime(); if (songComponent.songStartTime && this.beatsTimeOffset !== undefined && this.songCurrentTime !== currentTime) { this.songCurrentTime = currentTime; @@ -177,11 +177,10 @@ AFRAME.registerComponent('beat-loader', { } } - if (this.beatsTimeOffset !== undefined) { if (this.beatsTimeOffset <= 0) { this.el.sceneEl.emit('beatloaderpreloadfinish', null, false); - this.songCurrentTime = this.el.components.song.context.currentTime; + this.songCurrentTime = songComponent.getCurrentTime(); this.beatsTimeOffset = undefined; } else { this.beatsTimeOffset -= delta; diff --git a/src/components/song.js b/src/components/song.js index a3ae7f7..56347d2 100644 --- a/src/components/song.js +++ b/src/components/song.js @@ -197,5 +197,9 @@ AFRAME.registerComponent('song', { gain.setValueAtTime(BASE_VOLUME, this.context.currentTime); this.songStartTime = this.context.currentTime; this.source.start(); + }, + + getCurrentTime: function () { + return this.context.currentTime - this.songStartTime; } });