diff --git a/js/HuesCore.js b/js/HuesCore.js index ef1c979..322bf72 100644 --- a/js/HuesCore.js +++ b/js/HuesCore.js @@ -268,7 +268,6 @@ HuesCore.prototype.songDataUpdated = function() { HuesCore.prototype.resetAudio = function() { this.beatIndex = 0; - this.position = 0; this.songDataUpdated(); } diff --git a/js/SoundManager.js b/js/SoundManager.js index 2fe4c56..406346d 100644 --- a/js/SoundManager.js +++ b/js/SoundManager.js @@ -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; + }); }); } });