日期:2014-05-16 浏览次数:20369 次
<script>
function dot(au){
myAudio = new Audio();//这里去掉var从而将myAudio定义到window对象下,这样可以防止在Chrome中被GC回收的可能。
document.getElementById("audioBox").appendChild(myAudio);
//myAudio.loop = true;
myAudio.preload = true;
myAudio.controls = true;
myAudio.src = "a1.mp3";
myAudio.addEventListener('ended', playEndedHandler, false);
myAudio.play();
function playEndedHandler(e){
//myAudio.src = "a4.mp3";
myAudio.play();
}
}
</script>
<div id="audioBox"></div>
<script type="text/javascript">
window.onload = function(){
var myAudio = new Audio();
myAudio.preload = true;
myAudio.controls = true;
myAudio.src = "1.mp3";
myAudio.addEventListener('ended', playEndedHandler, false);
myAudio.play();
document.getElementById("audioBox").appendChild(myAudio);
myAudio.loop = false;//禁止循环,否则无法触发ended事件
function playEndedHandler(e){
myAudio.src = "3.mp3";
myAudio.play();
myAudio.removeEventListener('ended',playEndedHandler,false);//解除绑定,除非你要循环后一个音乐
}
}
</script>