diff --git a/src/components/audio-feedback.js b/src/components/audio-feedback.js index a0313fd0479fdc0048295500bf5165408c0dcba6..cee9abe0946b0b5c3e950879ae9c45de466b36b2 100644 --- a/src/components/audio-feedback.js +++ b/src/components/audio-feedback.js @@ -9,10 +9,6 @@ AFRAME.registerComponent("audio-feedback", { init: function() { // @TODO using an arbitrary timeout here which is very bad. Needs to wait on model loading and audio source being connected setTimeout(() => { - this.mat = this.el.object3D.getObjectByName( - "DodecAvatar_Head_0" - ).material; - const audioComponent = (this.data.audioSource || this.el).components[ "networked-audio-source" ]; @@ -20,6 +16,10 @@ AFRAME.registerComponent("audio-feedback", { const audioSource = audioComponent && audioComponent.sound; if (!audioSource) return; + this.mat = this.el.object3D.getObjectByName( + "DodecAvatar_Head_0" + ).material; + this.analyser = audioSource.context.createAnalyser(); this.levels = new Uint8Array(this.analyser.frequencyBinCount); audioSource.disconnect();