自动播放
<audio autoplay="autoplay" loop id="music">
<source src="http://music.163.com/song/media/outer/url?id=1308256434" audio="" >
</audio>
点击播放
<audio autoplay loop id="music">
<source src="http://music.163.com/song/media/outer/url?id=1308256434" audio="" >
</audio>
function onmusic(){
document.getElementById('music').play(); //播放
}
判断播放暂停
<div id="btn">播放暂停</div>
var audio = document.getElementById("music");
var btn = document.getElementById("btn");
btn.onclick = function () { //点击按钮播放停止
if (audio.paused) { //判断当前的状态是否为暂停,若是则点击播放,否则暂停
audio.play();
}else{
audio.pause();
}
};
完整实例