Se volete una versione che funziona per browser vecchio, ho fatto questa libreria:
function Sound(source,volume,loop)
{
this.source=source;
this.volume=volume;
this.loop=loop;
var son;
this.son=son;
this.finish=false;
this.stop=function()
{
document.body.removeChild(this.son);
}
this.start=function()
{
if(this.finish)return false;
this.son=document.createElement("embed");
this.son.setAttribute("src",this.source);
this.son.setAttribute("hidden","true");
this.son.setAttribute("volume",this.volume);
this.son.setAttribute("autostart","true");
this.son.setAttribute("loop",this.loop);
document.body.appendChild(this.son);
}
this.remove=function()
{
document.body.removeChild(this.son);
this.finish=true;
}
this.init=function(volume,loop)
{
this.finish=false;
this.volume=volume;
this.loop=loop;
}
}
Documentazione:
Sound
prende tre argomenti. L'url del suono, il volume (da 0 a 100) e il loop (true to loop, false not to loop).
stop
consentire a start
dopo (contrariamente a remove
).
init
reimpostare l'argomento volume e loop.
Esempio:
var foo=new Sound("url",100,true);
foo.start();
foo.stop();
foo.start();
foo.init(100,false);
foo.remove();
//Here you you cannot start foo any more
nei browser moderni, è possibile utilizzare [di HTML5 '