reset beatOffsetTime on clearBeats

This commit is contained in:
Kevin Ngo
2018-10-29 20:26:05 -07:00
parent 7b889d22b6
commit dc59bc9b3b
2 changed files with 8 additions and 3 deletions

View File

@@ -139,7 +139,8 @@ AFRAME.registerComponent('beat-loader', {
// Re-sync song with beats playback.
const songComponent = this.el.components.song;
const currentTime = songComponent.getCurrentTime();
if (songComponent.songStartTime && this.beatsTimeOffset !== undefined &&
if (currentTime !== undefined && this.beatsTimeOffset !== undefined &&
this.songCurrentTime !== currentTime) {
this.songCurrentTime = currentTime;
this.beatsTime = (this.songCurrentTime + this.data.beatAnticipationTime) * 1000;
@@ -175,6 +176,7 @@ AFRAME.registerComponent('beat-loader', {
}
}
// Update preload beat offset.
if (this.beatsTimeOffset !== undefined) {
if (this.beatsTimeOffset <= 0) {
this.el.sceneEl.emit('beatloaderpreloadfinish', null, false);
@@ -185,7 +187,7 @@ AFRAME.registerComponent('beat-loader', {
}
}
this.beatsTime = beatsTime + delta;
this.beatsTime += delta;
},
generateBeat: (function () {
@@ -302,7 +304,7 @@ AFRAME.registerComponent('beat-loader', {
*/
clearBeats: function () {
this.beatsTime = 0;
this.beatsTimeOffset = undefined;
this.beatsTimeOffset = this.data.beatAnticipationTime * 1000;
for (let i = 0; i < this.beatContainer.children.length; i++) {
let child = this.beatContainer.children[i];
if (child.components.beat) {

View File

@@ -132,6 +132,7 @@ AFRAME.registerComponent('song', {
this.source.stop();
this.source.disconnect();
this.source = null;
this.songStartTime = undefined;
},
victory: function () {
@@ -178,6 +179,7 @@ AFRAME.registerComponent('song', {
if (this.data.isBeatsPreloaded) { this.startAudio(); }
}, ONCE);
this.audioAnalyser.refreshSource();
this.songStartTime = undefined;
},
onWallHitStart: function () {
@@ -200,6 +202,7 @@ AFRAME.registerComponent('song', {
},
getCurrentTime: function () {
if (this.songStartTime === undefined) { return undefined; }
return this.context.currentTime - this.songStartTime;
}
});