Results 1 to 1 of 1

Thread: Audio Tag. Playlist, Shuffle, Loop

  1. #1
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default Audio Tag. Playlist, Shuffle, Loop

    EDIT: The code below works fine. The actual code I had on the page had wrong paths that prevented it from working correctly.
    I no longer need help with it. Thanks:

    Code:
    <audio id="audio" preload="auto" tabindex="0" controls="" type="audio/mpeg">
    </audio>
    <div id="playing">
    </div>
    
    var audio;
    var playlist;
    var tracks;
    var current;
    
    var musicarr = ["http://www.archive.org/download/CanonInD_261/CanoninD.mp3",
                    "http://www.archive.org/download/MoonlightSonata_755/Beethoven-MoonlightSonata.mp3",
                    "http://www.archive.org/download/bolero_69/Bolero.mp3",
                    "http://www.archive.org/download/onclassical-quality-wav-audio-files-of-classical-music/onclassical_demo_demicheli_geminiani_pieces_allegro-in-f-major_small-version_64kb.mp3",
                    "http://www.archive.org/download/onclassical-quality-wav-audio-files-of-classical-music/onclassical_demo_elysium_anonymous-elysium_the-young-false-man_small-version_live-and_restored_64kb.mp3",
                    "http://www.archive.org/download/onclassical-quality-wav-audio-files-of-classical-music/onclassical_demo_ensemble-la-tempesta_porpora_iii-notturno_iii-lezione_live_small-version_64kb.mp3",
                    "http://www.archive.org/download/onclassical-quality-wav-audio-files-of-classical-music/onclassical_demo_roccato_anonymous-roccato_riflessi_small-version_64kb.mp3"
                   ];
    shuffle(musicarr);
    
    init();
    function init(){
        current = 0;
        audio = $('audio');
        audio[0].volume = .40;
        len = musicarr.length;
    
        run(musicarr[current], audio[0]);
    
        audio[0].addEventListener('ended',function(e){
            current++;
            if(current == len){
                current = 0;
            }
            run(musicarr[current],audio[0]);
        });
    }
    
    function run(link, player){
            player.src = link;
            audio[0].load();
            audio[0].play();
            $('#playing').html("<ul><li><a>" + link+ "</a></li></ul>");     
    }
    
    function shuffle(array) {
      var currentIndex = array.length, temporaryValue, randomIndex ;
    
      // While there remain elements to shuffle...
      while (0 !== currentIndex) {
    
        // Pick a remaining element...
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex -= 1;
    
        // And swap it with the current element.
        temporaryValue = array[currentIndex];
        array[currentIndex] = array[randomIndex];
        array[randomIndex] = temporaryValue;
      }
    
      return array;
    }
    Last edited by KennyP; 03-14-2016 at 08:58 AM.

Similar Threads

  1. Replies: 9
    Last Post: 07-14-2014, 04:52 PM
  2. Vertical Slider with Shuffle Button
    By bbilal in forum Looking for such a script or service
    Replies: 0
    Last Post: 01-08-2013, 03:51 PM
  3. Replies: 3
    Last Post: 04-26-2009, 03:10 AM
  4. Dynamic playlist for audio player
    By unitedlocalbands in forum Looking for such a script or service
    Replies: 8
    Last Post: 08-04-2007, 11:14 PM
  5. shuffle music videos
    By cruelneo in forum HTML
    Replies: 0
    Last Post: 09-21-2005, 01:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •