Skip to content

Instantly share code, notes, and snippets.

@janily
Created January 3, 2016 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janily/e576e8124edb82752257 to your computer and use it in GitHub Desktop.
Save janily/e576e8124edb82752257 to your computer and use it in GitHub Desktop.
音乐控制
function HTML5Audio(url, loop) {
var audio = new Audio(url);
audio.autoplay = true;
audio.loop = loop || false; //是否循环
audio.play();
return {
end: function(callback) {
audio.addEventListener('ended', function() {
callback()
}, false);
}
}
}
$(function() {
$("button:first").click(function() {
//背景音乐
var audio1 = HTML5Audio('http://www.imooc.com/upload/media/one.mp3')
audio1.end(function() {
alert("音乐结束")
})
})
$("button:last").click(function() {
//循环播放那
var audio2 = Hmlt5Audio('http://www.imooc.com/upload/media/two.mp3', true)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment