
var loopAudio = new Audio(); 


function playLoop() {
    
    
    var playbtn = document.getElementById("playBtn");
    
   
    var l = document.getElementById("loops");
    var loopToPlay = l.options[l.selectedIndex].value;
    

    switch (playbtn.name){
        case "play":
            
           
            loopAudio.src = "../../data/loops/"+loopToPlay+".ogg";
            
      
            loopAudio.play();
            
         
            loopAudio.addEventListener("ended", function() {
                loopAudio.play();
            },true); 
            
           
            playbtn.name = "stop";
            playbtn.src = "/static/img/stop.png";
            break;
            
        case "stop":
            
           
            loopAudio.pause();
            loopAudio.currentTime=0;
            
           
            playbtn.name = "play";
            playbtn.src = "/static/img/play.png";
            break;
    }
}