diff --git a/src/components/beat-hit-sound.js b/src/components/beat-hit-sound.js index d1b80dd..4c5076c 100644 --- a/src/components/beat-hit-sound.js +++ b/src/components/beat-hit-sound.js @@ -1,4 +1,5 @@ var audioContext = new window.AudioContext(); +var sourceCreatedCallback; const LAYER_BOTTOM = 'bottom'; const LAYER_MIDDLE = 'middle'; @@ -50,7 +51,11 @@ AFRAME.registerComponent('beat-hit-sound', { init: function () { this.currentBeatEl = null; this.currentCutDirection = ''; + this.processSound = this.processSound.bind(this); + sourceCreatedCallback = this.sourceCreatedCallback.bind(this); + }, + play: function () { for (let i = 1; i <= 10; i++) { this.el.setAttribute(`sound__beathit${i}`, { poolSize: 4, @@ -65,26 +70,6 @@ AFRAME.registerComponent('beat-hit-sound', { src: `#hitSound${i}right` }); } - - this.processSound = this.processSound.bind(this); - }, - - play: function () { - // Kick three.js loader...Don't know why sometimes doesn't load. - for (let i = 1; i <= 10; i++) { - if (!this.el.components[`sound__beathit${i}`].loaded) { - this.el.setAttribute(`sound__beathit${i}`, 'src', ''); - this.el.setAttribute(`sound__beathit${i}`, 'src', `#hitSound${i}`); - } - if (!this.el.components[`sound__beathit${i}left`].loaded) { - this.el.setAttribute(`sound__beathit${i}left`, 'src', ''); - this.el.setAttribute(`sound__beathit${i}left`, 'src', `#hitSound${i}left`); - } - if (!this.el.components[`sound__beathit${i}right`].loaded) { - this.el.setAttribute(`sound__beathit${i}right`, 'src', ''); - this.el.setAttribute(`sound__beathit${i}right`, 'src', `#hitSound${i}right`); - } - } }, playSound: function (beatEl, cutDirection) {