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

@@ -16,6 +16,7 @@
<a-asset-item id="tunnelObj" src="assets/models/tunnel.obj"></a-asset-item>
<a-asset-item id="tunnelNeonObj" src="assets/models/tunnelneon.obj"></a-asset-item>
<audio id="beatHitSound" src="assets/sounds/beatHit.ogg"></audio>
<audio id="confirmSound" src="assets/sounds/beatHit.ogg"></audio>
<audio id="hoverSound" src="assets/sounds/hover.ogg"></audio>

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;