I'm creating a playlist with HTML5 and jQuery. My markup:
<ol class="playlist">
<li>
audio 1
<audio class="track" preload="none">
<source src="<?php echo $siteroot; ?>/audio/joao/docevapor/audio1.ogg" type="audio/ogg">
</audio>
</li>
<li>
audio 2
<audio class="track" preload="none">
<source src="<?php echo $siteroot; ?>/audio/joao/docevapor/audio2.ogg" type="audio/ogg">
</audio>
<li>
audio 3
<audio class="track" preload="none">
<source src="<?php echo $siteroot; ?>/audio/joao/docevapor/audio3.ogg" type="audio/ogg">
</audio>
</li>
</ol>
And my script:
$(function() {
if($('.playlist')) {
$('.playlist').find('li').prepend('<button class="control play">▶</button>');
$('.playlist li').on('click', '.play', function() {
var index = $(this).parent().index();
var track = $(this).parent().find('.track').eq(0);
$('.playlist .track').trigger('pause');
$('.playlist .play').removeClass('active');
$(this).addClass('active');
track.trigger('load').trigger('play');
});
}
});
I need that when a song in the playlist finishes its execution the next song in the playlist will play, until the last one. How to do this?