title: Jquery autoplay and autoplay next song
body: <p>I can't seem to find useful code to make my playlist autoplay the first song when site loads and then when the song finishes, autoplay the next song.</p>
  
  <p>I got this code following a tutorial, but they did not include these functions. I have looks all over and the code I have seen has not helped me with my issue.</p>
  
  <pre><code>var audio;
  
  //Hide pause buton
  $('#pause').hide();
  
  //Initialize Audio
  initAudio($('#playlist li:first-child'));
  
  
  //Initializer Function
  function initAudio(element){
      var song = element.attr('song')
      var title = element.text();
  
      //Create audio object
      audio = new Audio('media/' + song);
  
      if(!audio.currentTime){
          $('#duration').html('0.00');
      }
  
      $('#audio-player .title').text(title);
  
      $('#playlist li') .removeClass('active');
          element.addClass('active');
  
      }
  
      //PLay Button
      $('#play') .click(function(){
          audio.play();
          $('#play') .hide();
          $('#pause') .show();
          $('#duration') .fadeIn(400);
          showDuration();
  
      });
  
  
      //Pause Button
      $('#pause') .click(function(){
          audio.pause();
          $('#pause') .hide();
          $('#play') .show();
  
  
      });
  
      //Stop Button
      $('#stop') .click(function(){
          audio.pause();
          audio.currentTime = 0;
          $('#pause') .hide();
          $('#play') .show();
          $('#duration') .fadeOut(400);
  
      });
  
  
  
      //Next Button
      $('#next').click(function(){
          audio.pause();
          var next = $('#playlist li.active').next();
          if (next.length == 0) {
              next = $('#playlist li:first-child');
          }
          initAudio(next);
          audio.play();
          showDuration();
      });
  
      //Prev Button
      $('#prev') .click(function(){
          audio.pause();
          var prev = $('#playlist li.active').prev();
          if (next.length == 0){
              prev = $('playlist li:last-child');
          }
          initAudio (prev);
          audio.play();
          showDuration();
      });
  
  
  
      //Time Duration
  
      function showDuration(){
          $(audio).bind('timeupdate', function(){
              //Get Hours &amp; Minutes
              var s = parseInt (audio.currentTime % 60);
              var m = parseInt ((audio.currentTime)/ 60) % 60;
              //Add 0 if less than 10
              if(s &lt; 10){
                  s = '0' + s;
  
              }
              $('#duration').html (m + '.' + s);
              var value = 0;
              if(audio.currentTime &gt; 0) {
                  value = Math.floor((100 / audio.duration) * audio.currentTime);
  
              }
              $('#progress').css('width',value+'%');
          });
      }
  
      //Playlist Song Click
      $('#playlist li').click(function () {
          audio.pause();
          initAudio($(this));
          $('#play').hide();
          $('#pause').show();
          $('#duration').fadeIn(400);
          audio.play();
          showDuration();
      });
  
  
      //Volume Control
      $('#volume').change(function(){
      audio.volume = parseFloat(this.value / 10);
  });
  </code></pre>