workaround to fix sound component / audioloader not loading initially

This commit is contained in:
Kevin Ngo
2018-10-29 23:42:09 -07:00
parent 94d1c53933
commit e2654add5b
2 changed files with 11 additions and 1 deletions

View File

@@ -42,7 +42,7 @@ AFRAME.registerComponent('beat-hit-sound', {
this.currentCutDirection = '';
this.el.setAttribute('sound__beathit', {
poolSize: 12,
src: 'assets/sounds/beatHit.ogg',
src: '#beatHitSound',
volume: 0.5
});
this.processSound = this.processSound.bind(this);
@@ -50,6 +50,15 @@ AFRAME.registerComponent('beat-hit-sound', {
sourceCreatedCallback = this.sourceCreatedCallback.bind(this);
},
play: function () {
// Kick three.js loader...Don't know why sometimes doesn't load.
if (!this.el.components.sound__beathit.loaded) {
console.log('[beat-hit-sound] Kicking three.js AudioLoader / sound component...');
this.el.setAttribute('sound__beathit', 'src', '');
this.el.setAttribute('sound__beathit', 'src', '#beatHitSound');
}
},
playSound: function (beatEl, cutDirection) {
const soundPool = this.el.components.sound__beathit;
this.currentBeatEl = beatEl;