Race condition fix

alternate-visualiser
William Toohey 10 years ago
parent bf4cfe4da5
commit c88c9839eb
  1. 1
      js/HuesCore.js
  2. 14
      js/SoundManager.js

@ -268,7 +268,6 @@ HuesCore.prototype.songDataUpdated = function() {
HuesCore.prototype.resetAudio = function() {
this.beatIndex = 0;
this.position = 0;
this.songDataUpdated();
}

@ -101,6 +101,10 @@ SoundManager.prototype.playSong = function(song, playBuild, callback) {
this.loadBuffer(song, function() {
// To prevent race condition if you press "next" twice fast
if(song == that.song) {
// more racing than the Melbourne Cup
try {
that.bufSource.stop(0);
} catch(err) {}
that.bufSource = that.context.createBufferSource();
that.bufSource.buffer = that.buffer;
that.bufSource.loop = true;
@ -108,9 +112,6 @@ SoundManager.prototype.playSong = function(song, playBuild, callback) {
that.bufSource.loopEnd = that.buffer.duration;
that.bufSource.connect(that.gainNode);
if(callback)
callback();
// This fixes sync issues on Firefox and slow machines.
that.context.suspend().then(function() {
if(playBuild) {
@ -121,8 +122,11 @@ SoundManager.prototype.playSong = function(song, playBuild, callback) {
that.bufSource.start(0, that.loopStart);
that.startTime = that.context.currentTime;
}
that.context.resume();
that.playing = true;
that.context.resume().then(function() {
if(callback)
callback();
that.playing = true;
});
});
}
});

Loading…
Cancel
Save