I have been working on adding background music to a Glitch project. I followed the Aframe.io documents to create a sound component and set it to automatically play upon running, however, when I try to run the project, the sound does not play automatically on my laptop. I have to open the Aframe inspector and un-pause my project for the music to begin. For some reason, I have not encountered this issue when I tried the same project on my phone. The sound played as expected once the program is up and running. I am not sure what is causing the sound to malfunction but any help is greatly appreciated. Here is the project I am working on: https://glitch.com/edit/#!/animation-animate?path=index.html%3A15%3A23
2 Answers
when working with sounds natively with Aframe, I had the same problem and one of the recommendations that I can give you is to play sounds with the HowlerJS sound library, which is compatible with most frameworks and also compatible with A-Frame
I share their page and the documentation, this library is very easy to use and implement to the project https://howlerjs.com/ https://github.com/goldfire/howler.js#documentation

- 21
- 1
-
unfortunately, this is even more the experience I have in 2022. Would be cool to see an integration built, as howl can also support spatial audio in theory. – Kyle Baker Sep 19 '22 at 20:14
Autoplay audio on most modern browsers requires user interaction before enabling audio. You can put a div in front of your scene that upon click starts playing your background audio.
Check out a related SO question / answer for video autoplay that should help: Autoplaying videosphere from A-frame is not working on any browser(Safari/Chrome)
Another user on A-Frame discord provided this example demo: https://aframe-autoplay-background-music.glitch.me/

- 567
- 4
- 16
-
They seemed to have solved the problem through tweaks on the javascript part, but I am unfamiliar with javascript. Is there any possible solution to this using only aframe html? – Jun Oct 19 '20 at 02:53