开发者

HTML5/JavaScript/jQuery audio playlist

开发者 https://www.devze.com 2023-04-02 23:35 出处:网络
I\'ve got this JavaScript/jquery code: $(document).ready(function() { var audioElement = document.createElement(\'audio\');

I've got this JavaScript/jquery code:

$(document).ready(function() {
var audioElement = document.createElement('audio');
var secondtrack = 'hangover.ogg';
audioElement.setAttribute('src', 'hangover.ogg');
audioElement.load()
audioElement.addEventListener("load", function() { 
    audioElement.play(); 
}, true);

$('#play').click(function() {
    audioElement.play();
});
$('#pause').click(function() {
    audioElemen开发者_JAVA技巧t.pause();
});
});

How could I get another song started after the first ended?


The AUDIO element should fire a "ended" event though I am not sure how well this is supported at the moment.

So you could try something like that:

audioElement.addEventListener('ended', function () {
    // Play another song
});

See also: http://dev.w3.org/html5/spec/Overview.html#event-media-ended

0

精彩评论

暂无评论...
验证码 换一张
取 消