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; } });