0

I'm trying to build an A-Frame scene where a car drives by the user, and I need the sound of the car to start playing as the car starts moving. For example:

<a-collada-model id="car" src="#car-dae" position="-0.7 0 -100" rotation="0 90 0">
  <a-animation attribute="position"
         dur="7000"
         begin="model-loaded"
         fill="forwards"
         to="-0.7 0 20"
         repeat="0"
  ></a-animation>
</a-collada-model>

Can I put a sound component on the animation? If not, how should I go about having the sound play at the same time as the animation? I tried putting the sound component on the collada model and gave it a on:model-loaded (same event as the animation), but this never played the sound. In fact, the only way I seem to be able to get the sound to play is using autoplay. Any ideas?

If it helps, all of my code is in this git repo under carChase.html

https://github.com/zeekw/aFrameTests

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
Isaac Wasserman
  • 1,461
  • 4
  • 19
  • 39
  • Adding `sound="src: #car-sound; autoplay: true; volume: 10"` to the collada model entity will do the trick. Try it. It's well synced with the movement of the car. – thoragio Dec 28 '16 at 11:48
  • @thoragio What makes it synced with the movement of the car? – Isaac Wasserman Dec 28 '16 at 15:42
  • Well, when I load it with the sound attribute as I described above, the movement of the car and the sound seem in good sync. IOW, you see the car on the horizon moving toward you and as it gets closer the engine sound gets louder until it passes right under you. – thoragio Dec 28 '16 at 16:39
  • @thoragio , but depending on the user's internet connection and gpu, the car may start moving at a different time – Isaac Wasserman Dec 28 '16 at 17:11
  • You have the sound and model inside the a-asset tags, so A-Frame will load them up first before rendering the scene. See: https://aframe.io/docs/0.4.0/core/asset-management-system.html – thoragio Dec 30 '16 at 09:37

1 Answers1

1

Did you try putting the sound component on the model, or as a child of it?

<a-collada-model src="#car-dae" sound="on: model-loaded; src: #car-sound">
ngokevin
  • 12,980
  • 2
  • 38
  • 84
  • @ngokevin `on: model-loaded` does not play the sound when I try it, but `autoplay: true` does. – thoragio Dec 30 '16 at 09:43
  • Okay, as a workaround, you can manually add a JS event listener to the model, and then play the sound like `el.components.sound.playSound()`. Want to file an issue? – ngokevin Dec 30 '16 at 19:37