vueper-slides icon indicating copy to clipboard operation
vueper-slides copied to clipboard

Carousel with Images plus videos not stopping autoplay

Open nicoagp opened this issue 3 years ago • 0 comments

Reproduction:

I added an array with a mix of images and videos (1 youtube and 1 mp4). When swapping between videos it pauses the previous video ok but when I swap from image - video - image, the video keeps autoplaying.

Image -> video -> image (pause not working ok) video <-> video ( pause prev video works ok)

Is it a bug ? I something I am missing ?

I solved it this way (but would like to know if I am missing something , can the code below be better or it is actually a bug)

handleBeforeSlide() {
      console.log('handle before slide')
      var videos = document.querySelectorAll('video');
      var iframes = document.querySelectorAll('iframe');

      if(videos.length) {
        videos.forEach(function(item) {
          if(item) { item.pause() }
        });
      }

      if(iframes.length) {
        iframes.forEach(function(item) {
          if(item) { item.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'pauseVideo' }), '*'); }
        });
      }

    },

Thank you, Nice library

nicoagp avatar Feb 24 '22 06:02 nicoagp