Audio Playlist

<html> <head> <meta name="description" content="CDN Bootstrap"> <link href="//" rel="stylesheet" > <script src="//"></script> </head> <body> <div class="copy">Audio playlist that can play audio on a loop. You can select the next track and it will resume from there. Hide the content and it makes a nice player for background audio. This runs fine on save but the link open the mp3 if you click Run at the bottom and then select a track. The default volume level can be set in the JS. Bootstrap is not a necessity</div> <div class="panel panel-default audio-panel"> <audio id="audio" autoplay preload="auto" tabindex="0" controls> <source src=""> </audio> </div> <ul id="playlist"> <li class="active list-group-item"> <a href=""> Sample 1 </a> </li> <li class="list-group-item"> <a href=""> Sample 2 </a> </li> <li class="list-group-item"> <a href=""> Sample 3 </a> </li> <li class="last"> <a href=""> Sample 3 </a> </li> </ul> </body> </html>
.copy{ margin:20px; padding:20px; border-style:solid; border-width:1px; border-color: #ddd; -webkit-border-radius:3px; border-radius:3px; font-size:18px; } .panel{ margin: 20px; padding:0px; height:34px;} .audio-panel{border:none !important;} #playlist,audio{width:100%;} .active a{color:#fff;text-decoration:none;} ul{list-style:none; margin:0px; padding:20px;} li{margin:0px; padding:0px;} li, a{transition:all 0.5s;} a{ text-decoration:none; color:#fff;} a{display:block; position:relative; width:100%;} li a{display:block; text-decoration:none;} li:hover{background-color:#333;} li a:hover{text-decoration:none; color: #fff;} a{color:#fff; text-decoration:none;} .last{display:none;}
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 = 0.5; 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(); }
Expand for more options Login