Created
January 3, 2016 15:31
-
-
Save janily/e576e8124edb82752257 to your computer and use it in GitHub Desktop.
音乐控制
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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