Nếu bạn muốn có một phiên bản mà làm việc cho trình duyệt cũ, tôi đã thực hiện thư viện này:
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;
}
}
Tài liệu:
Sound
mất ba đối số. Url của âm thanh, âm lượng (từ 0 đến 100) và vòng lặp (true to loop, false không lặp).
stop
cho phép start
sau (trái với remove
).
init
đặt lại âm lượng và vòng lặp đối số.
Ví dụ:
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
Trong trình duyệt hiện đại, bạn có thể sử dụng [HTML5 của '