Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carousel with Images plus videos not stopping autoplay #174

Open
nicoagp opened this issue Feb 24, 2022 · 0 comments
Open

Carousel with Images plus videos not stopping autoplay #174

nicoagp opened this issue Feb 24, 2022 · 0 comments

Comments

@nicoagp
Copy link

nicoagp commented Feb 24, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant