Play multiple sounds simultaneously

The built-in play function has some limitations on the Windows platform. Specifically, it is unable to handle filenames that are longer than 127 character, and it cannot play more than one sound at a time.

The playBetter function below is designed to address these issues. Just include this function in your widget's onLoad JavaScript, and use playBetter instead of any play calls you may have.

function playBetter(path, truncate) { switch (system.platform) { case "windows": if (!playBetter.bObjs) playBetter.bObjs = new Array; if (truncate) { for (var i = 0; i < playBetter.bObjs.length; i++) playBetter.bObjs[i].controls.stop; }     if (path) { for (var i = 0; i <= playBetter.bObjs.length; i++) { if (i == playBetter.bObjs.length) playBetter.bObjs.push(COM.createObject("WMPlayer.OCX.7")); var playState = playBetter.bObjs[i].playState; if (playState == 3 || playState == 6) continue; playBetter.bObjs[i].URL = path; playBetter.bObjs[i].controls.play; break; }     }      break; default: play(path, truncate); break; } }

Advanced use
By default, playBetter creates as few unique instances of a Windows Media Player COM object as are necessary to play all the sound files requested.

Be careful not to call playBetter in a tight loop - if many sounds are playing simultaneously, your widget will use a lot of memory, because each instance requires its own chunk of memory.

To stop all currently playing sounds, you can make the following call: playBetter("", true);

Troubleshooting
Konfabulator may report the following error when using this on some Windows PCs:
 * uncaught exception: Unable to create object: The specified module could not be found.

This is caused by Windows Media Player DLLs not being properly registered. To fix it, simply run the following two commands: regsvr32.exe wmp.dll regsvr32.exe wmpdxm.dll