Si desea una versión que funciona para navegador de edad, he hecho esta biblioteca:
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;
}
}
Documentación:
Sound
tiene tres argumentos. La url del sonido, el volumen (de 0 a 100) y el bucle (verdadero en bucle, falso en no bucle).
stop
permiten a start
después (contrario a remove
).
init
restablecer el volumen del argumento y el ciclo.
Ejemplo:
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
En los navegadores modernos, se puede usar [de HTML5 '