Jump to content
PixelFox

Add shuffle button in audio player, and auto shuffle

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();
        };

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...