Jon Herrera Jon Herrera - 2 months ago 9
Javascript Question

Play() assets vs. entity in aframe

I'm able to .play() assets, but not entities in the following structure:

<a-scene>
<a-assets>
<audio id="assetNarration" src="snd/dt_narration_1.mp3" preload="auto" autoplay="false">
<video id="video" src="video/Open_Sky.mp4" autoplay="false" loop></video>
</a-assets>
<a-sound id="entityNarration" src="#assetNarration" autoplay="false" position="0 5 0" volume="0.5"></a-sound>
<a-videosphere id="v1" src="#video" autoplay="false" rotation="0 90 0"></a-videosphere>
</a-scene>


This allows me to trigger:

var nar = document.querySelector('#assetNarration');
var vid = document.querySelector('#video');
nar.play();
vid.play();


..but not

var nar = document.querySelector('#entityNarration');
var vid = document.querySelector('#v1');
nar.play();
vid.play();


The major difference with this is that I'm setting volume and position values on the entity, which are ignored if I trigger .play() directly on the asset.

Answer

Perhaps try el.components.sound.playSound(). Else, try passing an inline URL directly since it creates an audio buffer which is a bit more flexible.