I need to add a soundtrack to my game. The audio file is m4a.
// Get a reference to the audio element
const audio = new Audio("path/to/background-music.mp3");
// Set the loop attribute to true for looping
audio.loop = true;
// Play the background music
Make sure to replace
"path/to/background-music.mp3" with the actual path to your background music file.
Hope this helps
The copying and pasting messed up a bit lol.
Doesn’t seem to work for me, does it work for you?
I can try converting it to mp3.
Didn’t work. It could just be me.
Sound and video in HTML will not play until once user action happens. So basically, you’ll need to add something that either says “click to enable sound” or “Click to begin game”. Either will confirm that the user is active and let you play audio. (If I’m understanding correctly, you are trying to autoplay sound as soon as the user enters your website.)