javascript - How do I stop my html5 audio playlist from looping? -
i've set play list our website. got auto play stop can't stop each track looping. last song in list stops after played rest keep going , going. here javascript being used. missing something?
</style> <script> var audio; var playlist; var tracks; var current; init(); function init(){ current = 0; audio = $('#audio'); playlist = $('#playlist'); tracks = playlist.find('li a'); len = tracks.length - 1; audio[0].volume = .20; audio[0].play(); playlist.find('a').click(function(e){ e.preventdefault(); link = $(this); current = link.parent().index(); run(link, audio[0]); }); audio[0].addeventlistener('ended',function(e){ current++; if(current == len){ current = 0; link = playlist.find('a')[0]; }else{ link = playlist.find('a')[current]; } run($(link),audio[0]); }); } function run(link, player){ player.src = link.attr('href'); par = link.parent(); par.addclass('active').siblings().removeclass('active'); audio[0].load(); audio[0].play(); } </script>
Comments
Post a Comment