i’ve been working on adding background music to the website (much like melonking.net). wavs or mp3s would take a while to load (or i’d have to decimate the audio quality- which is what melonking does), and i can’t just use a more effecient format such as opus (which is usually used in WebM, google’s foss video format) since some systems won’t be able to play it (looking at you apple). so instead, my solution was just to use midi- except modern web browser can’t play midi either.. enter midijs (not midi.js, that’s apparently an entierly different library). it was pretty easy to set up, all you do is host some midis somewhere and then do MIDIjs.play(“/Music/bgm/maniaStudiopolisAct1.mid”). i have a whole folder of midis to play at random, so i get a random number, round it so it’s not so scary. and in my case i have an array with all of the file names for the song, since i wanted to keep the song titles and not just call them BGM1, 2 , 3, and so on. if you want, you can even make another couple arrays to store metadata, like song title, artist, etc.
there are a couple problems with background music though:
most modern browsers have autoplay off or set to “automatic”, which means audio won’t start playing until the user does something (like clicking). my site’s not very interactive though, so clicking will probably take them to another page- which means they still have to click to hear the music, since it’s per page
there’s also no easy way of detecting this using MIDIjs, since it always returns “undefined” and doesn’t throw an error.
so the only way to detect autoplay is to try to create an audiocontext yourself- and the only way to do that (as far as i know) is to play an audio file..
so for now, the testing site just has a big ‘ol banner on the front page that tells you to turn on your autoplay. it’ll be fine for the time being, but eventually when music gets added to the main site in the forseeable future i would like to have a better solution)
edit: the testing site is live!
also remix 4 sounds like absolute garbage in the default midijs soundfont I apologize