Jump to content

Add shuffle button in audio player, and auto shuffle


PixelFox

Recommended Posts

im editting a javascript of an audio player for HTML5, and it doesnt have any shuffle option, i wanted to add it manually and be activated by default. In the code i show, i show the functions that plays o passes to the next song, so you can see the function names im using.

im actually studying web design (basic level) and i havent seen javascript yet, so i understand so basic how it works, so i can edit a few things from a copied source. I obviously googled what im asking here, but i couldnt find any answer that i can understand, or make it work, just found some stuff that make things harder, using strings in the names or things like that to shuffle the songs, adding a lot of (i think) unnecesary code. I need a function that skips a song a random number of times, or such. but i dont know how to do it

 

Code:

 

function playAudio() {
            song.play();

            tracker.slider("option", "max", song.duration);

            $('.play').addClass('hidden');
            $('.pause').addClass('visible');
        }
        function stopAudio() {
            song.pause();

            $('.play').removeClass('hidden');
            $('.pause').removeClass('visible');
        }
        
        // play click
        $('.play').click(function (e) {
            e.preventDefault();

            playAudio();
        });

        // forward click
        $('.fwd').click(function (e) {
            e.preventDefault();

            stopAudio();

            var next = $('.playlist li.active').next();
            if (next.length == 0) {
                next = $('.playlist li:first-child');
            }
            initAudio(next);
        });  
        
        //autoplay
        window.onload = function(e) {
            playAudio();
        };

 

Link to comment
Share on other sites

An <audio> element just holds one single audio file. There may be a Javascript program that's changing which file the element plays, but I'm not seeing it in the code you showed. There are variables and functions that have not been declared, so this is clearly not all the code. I can't give any help without seeing all the code related to the sound player.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...