fix inaccurate current time in preload

This commit is contained in:
Kevin Ngo
2018-10-26 12:28:54 -07:00
parent 80316c066e
commit 308df53ea0
2 changed files with 6 additions and 3 deletions

View File

@@ -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;

View File

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