Jon Herrera Jon Herrera - 1 year ago 108
Javascript Question

Play() assets vs. entity in aframe

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

<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-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>

This allows me to trigger:

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

..but not

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

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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download