4 ms·
Unfortunately limitations on mobile audio will make this next to impossible to work on mobile for the time being. I wrote howler.js (http://howlerjs.com http://
by james33 13y ago
Unfortunately limitations on mobile audio will make this next to impossible to work on mobile for the time being. I wrote howler.js (http://howlerjs.com http://howlerjs.com) to solve this issue, but I'm guessing your source audio files are too large to use Web Audio reliably on mobile (this would be the only way to play multiple sounds at the same time).
- wavefunction 13y agoThere is another way actually, use an HTML5 Audio tag and Base64 encode the audio files, then load that data via JavaScript into the Audio tag. I really should probably write this up on my blog... I will - and post it on HN but here's a quick overview. I'm doing this for a JavaScript library I'm working on for form-validation for the visually-impaired (coming soon!) I dynamically create a pool of audio tags via var audioTag = document.createElement("audio") then audioTag.setAttribute("autoplay","autoplay"); then audioTag.src = strSound; You don't even have to attach them to the DOM either from my experience so far (cross-browser!), just maintain the reference in memory. Then I do some eventing magic for forms and validation stuff, loading the audio from strings of Base64 encoded mp3s or wavs. This way I can package the audio I use inside the JavaScript that hooks up all the form events. And make it easy for others to override my audio samples with their own just by over-writing the strings in memory via their own .js file include.
- wavefunction 13y agoI should note that a pool of audio tags allows you to play multiple sounds at once. I've tested my lib with up to 200 simultaneous samples playing at once on a lark, since I don't need anywhere near that sort of coverage.
- gabemart 13y agoThanks, this looks interesting. Do you have a setup using this trick live on the web anywhere?
- wavefunction 13y agoI'll post it up this evening when I get home and drop you a link, thanks for the interest!
- james33 13y agoInteresting, I do a lot of audio work in the browser and somehow I've never come across this trick. Does it work on iOS?
- wavefunction 13y agoI'm pretty sure it does as I vaguely remember testing my proof-of-concept via the iPhone Simulator in xCode, though I haven't touched it in a bit with the holidays. I'm working up a simplified example to post right now. My library has a lot of extraneous stuff related to cross-browser eventing and integrates with browser extensions, so I think it would be needlessly confusing to illustrate what we're discussing
- scaphandre 13y agoWhat do you mean impossible on mobile? I've been listening to this on a Nexus 5 for 30 mins. It played straight away on Chrome. Continues playing in background tab right now.