Embed song in HTML w/o file

Viewed 63

I'm designing a mini game that would be generated with HTML and JS on smartphone. It would be offline and won't be able to access any files.

So I was wondering how to embed a basic music in it and some sound design.

I see 2 options :

  • Make a sound generator with JS, and design a sound that could play this generator (something like this link)

  • Convert a low-fi mp3/ogg or other to base64 and add it directly in the HTML (src="data:audio/mp3;base64...")

The first method must be the lighter but could be difficult at the moment to design the song. And maybe not that light for the hardware?

The second method would be the easier to work with but because of the amount of data I don't know if it's a good option.

Any suggestions for one of those methods? Or maybe you have a better idea?

1 Answers

The game will probably need to be distributed to the phones somehow, so you should be able to incorporate not just HTML and JS into the distribution package, but also other asset files - like images and sound files. If that's the case, there's no need to try to embed the music into the HTML (option 2). Just ship an MP3 file with the music that you want to play as a part of that package.

Related