A hypothetical method for simple JavaScript fired sound-effects on the Wii™ and other Flash-enabled systems.

In an attempt to make a DHTML app targeted toward the Nintendo Wii™'s Internet Channel (Opera) browser, I'd run into the problem that the Wii™ does not inherently support MP3 audio and has no native player plugin. However, it does support Flash™. I, on the other hand, cannot, given my salary and other desires. So, what I needed was a simple Flash™ plugin that could respond to information from outside JavaScript and play a short sound effect. I was hoping for some manner of background-running Flash™ applet that would respond to function calls, but the Wii™'s Flash implementation did not support LiveConnect, the normal Opera way of interfacing JS to Flash™. So, my method is a little more brute-force. I can still pass variables to the Flash™ applet by way of the query string (parameters added to the filename) so I have just resorted to dynamically spawning a new Flash™ applet through JavaScript, every single time I want a sound to play. The applet itself is small and simple-- it's a 4px-blank square simply loads the MP3 file specified, plays it, then fires a "callback" JavaScript function when it's finished in order to notify the outside world. The callback JS function then destroys the Flash™ object.

One further development may have to do with memory use. I don't know whether destroying a plugin in the DOM actually frees its memory. If the Wii™ browser supports IFrames well enough, I may just use a pseudo-AJAX method of reloading, instead of appending, the Flash™ files into an IFrame. In order to support polyphony, I might just keep a tally (using the callbacks) of whether any files are loading, then "flush" (reload the IFrame document) once none are playing. This would allow the browser's innate memory and cache management to take care of cleaning, and make sure the device's slim memory constraints are not overrun.

Of course, the feasibility of this on the Wii™ is still up in the air. I'm currently at work, where the good tools are, but I have no machine to test on. Having done the heavy lifting (Flash file creation) here, I'll now go home, to slightly lesser tools, and test it on the live box. Even if it doesn't work on the Wii™, it's still quite a useful bit of code-- much easier than trying to play sound effects natively using whatever media plugin they may have installed.

The Flash file is here: sounder.swf, and the JS code is inline if you're interested.


Hit the button, make the sound. The boxes below are the Flash objects, which would normally be pushed off-screen.