2

I created an audio playlist using <ul> and <li>, this JavaScript code automatically plays the next song when one song ends and its working well.

But I have the tracks in a slider, and I want the slider to move along, as the song changes.

Is there a way I can have this JavaScript click the button for the next slide as well?

Code for next slide:

<a class="lSNext"></a>

JavaScript:

$(window).load(function(){
  var audio;
  var playlist;
  var tracks;
  var current;

  init();
  function init(){
    current = 0;
    audio = $('audio');
    playlist = $('#playlist');
    tracks = playlist.find('li a');
    len = tracks.length - 1;
    audio[0].volume = 1;
    audio[0].play();
    playlist.find('a').click(function(e){
      e.preventDefault();
      link = $(this);
      current = link.parent().index();
      run(link, audio[0]);
    });
    audio[0].addEventListener('ended',function(e){
      current++;
      if(current == len){
        current = 0;
        link = playlist.find('a')[0];
      }else{
        link = playlist.find('a')[current];    
      }
      run($(link),audio[0]);
    });
  }
  function run(link, player){
    player.src = link.attr('href');
    par = link.parent();
    par.addClass('active').siblings().removeClass('active');
    audio[0].load();
    audio[0].play();
  }
});//]]> 
Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
  • Maybe this post can help you http://stackoverflow.com/questions/773639/how-can-i-simulate-an-anchor-click-via-jquery – Alberto Jun 29 '16 at 10:37
  • Can you show enough of your HTML that we can reproduce the problem? Including the slider and whatever other components are directly related to your problem. Please read the "*[MCVE]*" guidelines to see what we expect, and need, in order to help you (and provide useful guidance for future visitors). – David Thomas Jun 29 '16 at 10:38
  • change "a" for "input" ;) – HudsonPH Jun 29 '16 at 10:39

2 Answers2

2

Add this code

$('.lSNext').click();
Nuhel
  • 186
  • 9
2

use

$('.lSNext').click();

after this line ( Inside This Function)

audio[0].addEventListener('ended',function(e){
Mamunur Rashid
  • 732
  • 4
  • 22