Skip to content Skip to sidebar Skip to footer

Html5/jquery Audio Shuffle Onclick

I have a simple HTML5 audio playlist and I would like the user to click a 'shuffle' button and shuffle the audio but I don't know the best way to go about this. I'm using audio.js

Solution 1:

Here is the logic for shuffle button. You'll have to write in the code to the get the track to play but it shouldn't be that difficult. I added a class to the ul called "tracks".

 $(".shufflebutton").click(function() {
        var trackCount = $(".tracks li").length;
        console.log('trackCount:' + trackCount);
         /* Pick random number between 1 and trackCount */var randomNum = Math.ceil(Math.random()*trackCount); 
        console.log("randomNum:" + randomNum);     
      });

Full code example here: http://jsfiddle.net/F8w8r/

Post a Comment for "Html5/jquery Audio Shuffle Onclick"