/** Music player * @param obj player ID * @param file Audio file mp3:ogg: * @param loop whether loop/function Audioplayer (ID, file,
Loop) {var audioplayer = document.getElementById (ID);
if (audioplayer!=null) {document.body.removeChild (Audioplayer);
} if (typeof (file)!= ' undefined ') {if (Navigator.userAgent.indexOf ("MSIE") >0) {//IE
var player = document.createelement (' bgsound ');
Player.id = ID;
player.src = file[' mp3 '];
Player.setattribute (' Autostart ', ' true ');
if (loop) {player.setattribute (' Loop ', ' infinite ');
} document.body.appendChild (player);
}else{//Other FF chome Safari Opera var player = document.createelement (' audio ');
Player.id = ID;
Player.setattribute (' AutoPlay ', ' AutoPlay ');
if (loop) {player.setattribute (' Loop ', ' Loop '); } docuMent.body.appendChild (player);
var mp3 = document.createelement (' source ');
mp3.src = file[' mp3 '];
Mp3.type= ' Audio/mpeg ';
Player.appendchild (mp3);
var ogg = document.createelement (' source ');
OGG.SRC = file[' ogg '];
Ogg.type= ' Audio/ogg ';
Player.appendchild (OGG); }
}
}
Demo:
var file = [];
file[' mp3 '] = ' 1.mp3 ';
file[' ogg ' = ' 1.ogg ';
Audioplayer (' Audioplane ', file, true); Play
Audioplayer (' Audioplane ');/stop