Talk:Play multiple sounds simultaneously

I thought I might share a modified version of this excellent function which includes some error checking and self-correction if the required DLLs are not registered correctly. I'm going to use this in an update to my Info URL Widget:

function playBetter(path, truncate) { try { 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) { try { playBetter.bObjs.push(COM.createObject('WMPlayer.OCX.7')); } catch (ex) { log('Error creating COM component: ' + ex); log('Registering controls: '                + runCommand('regsvr32.exe /s wmp.dll; regsvr32.exe /s wmpdxm.dll')); try { playBetter.bObjs.push(COM.createObject('WMPlayer.OCX.7')); } catch (ex) { log('Error creating COM component: ' + ex); return false; }              }             }             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; }  } catch(e) { log('Error in playBetter: ' + e); } }


 * Putting things in try/catch is definitely a good idea - but I think that registering DLLs without the user approving it is possibly not so good. This could especially cause problems if, for some reason, the user does not have Windows Media Player, as every time a sound is played, the function would attempt to register nonexistent DLLs. -Slthytove 14:15, 15 Nov 2005 (UTC)