Notes on minim.JS: fixes for potential problems

I had an issue with minim.js that I fixed but I thought I would post it here as a general piece of advice for people using it.

I have been working on an audio musical sampler type thing. Press a button, play a sound. Things would work fine in Firefox, but in Chrome sounds would play once but not twice. First time triggering? Worked fine. Second? Nothing. No errors in the console, either.

Long story short, it seems to be some kind of issue with the HTML 5 audio implementation. Minim.js is really just binding basic HTML 5 audio to a certain set of limited Minim functionality. So, there is a known problem with Chrome and HTML 5 audio doing the behavior I described above. In order to fix it, you have to load(); your audio right before you play(); it.

For a quick fix: open up your minim.js file, and find this.play = function() {. This is what gets called when your processing.js minim object performs .play(); functionality. Under this javascript function you will see this line:

audio.play();

Simply add a line above that like this:

audio.load();
audio.play();

Now your processing.js program will work fine in Firefox and Chrome.

Another separate issue, if you are having trouble using minim.js.

I was also having issues adjusting the volume on my minim objects. minimObject.volume = .05 or anything like that wouldn't work. Not sure why. What I wound up doing was writing a function in minim.js file to set the volume. Underneath the mute and unmute functions, I added one of my own:

this.setVolume = function(flt) {
audio.volume = flt;
};

Then in my processing program, all I would need to do is:

minimObject.setVolume(.05);

And it works. HTML 5 volume is measured from 0 to 1, so make sure whatever you are passing is a float.

Hope this helps and saves people some time.

Sign In or Register to comment.