Iframe youtube video does not play second time when switching to an another video in the list and come back

29 Views Asked by At

I am trying to loop list of iframe videos. If one video is playing others are hidden. When I switch to another video and come back to the previous video, it does not show and play.

This is my code, what am I doing wrong?

  for (var i = 0; i < youtube.length; i++) {
                                 
    $(youtube[i]).on('hidden.bs.collapse', function () {
       $('iframe').attr('src', '');
     });

    $(youtube[i]).on('show.bs.collapse', function () {
       $('iframe').attr('src', "https://www.youtube.com/embed/" + this.dataset.embed + "?rel=0&showinfo=0&autoplay=1");
     });
  }
0

There are 0 best solutions below