Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Watson 118 posts 384 karma points
    Dec 09, 2020 @ 01:02
    Mark Watson
    0

    Syncing video with Slick carousel

    We are using Slick Carousel with video in the slider. There are 3 slides with a different video in each. All the videos are the same size and are all 6 seconds long. The slider is set to change after 6 seconds.

    So in theory the videos should start when each slider is displayed. unfortunately this is not the case and over time the videos become progressively out of sync.

    The site and videos are both hosted on umbraco cloud. Does anyone know how to sync these videos so they start to play when the slider is displayed each time.

    // BANNER
            // PLAYS VIDEO IN BANNER
            $('.usn_cmp_banner .slides').on('init', function(slick){
                $('.usn_cmp_banner video').each(function () {
                    this.play();
                });
            });
            // ALL CAROUSELS
            $(".component:not(.usn_cmp_banner) .slides, footer#site-footer .slides").slick({
                rtl: rtl_slick(),
                infinite: true,
                speed: 600,
                adaptiveHeight: true,
                pauseOnFocus: false,
                pauseOnHover: false,
                prevArrow: '<div class="slick-prev"><i class="icon usn_ion-ios-arrow-back"></i>',
                nextArrow: '<div class="slick-next"><i class="icon usn_ion-ios-arrow-forward"></i>'
            });
    
  • Stephen Barr 2 posts 73 karma points
    Dec 09, 2020 @ 08:01
    Stephen Barr
    0

    Hi,

    It might be worth looking at the slick 'beforeChange' event. Here, you have access to the current slide and to the next slide, so you should be able to stop the current video playing, and then start the next video playing.

  • Mark Watson 118 posts 384 karma points
    Dec 11, 2020 @ 03:43
    Mark Watson
    0

    Thanks Stephen I have tried this a couple of ways but neither work for me. Any idea where i am going wrong.

     // On slide change, pause all videos
            $('.component.usn_cmp_banner .slides, .swp .slides').on('beforeChange', function(event, slick, currentSlide, nextSlide){
      $('video').each(function() {
        $(this).get(0).pause();
      });
    });
    
    // On slide chnage, play a video inside the current slide
    $('.component.usn_cmp_banner .slides, .swp .slides').on('afterChange', function(event, slick, currentSlide, nextSlide){
      if( $('.project-slide.slick-current').find('video').length !== 0) {
        $(".component.usn_cmp_banner .slides, .swp .slides .slick-current video")[0].play();
      }
    });
    

    and

      $(document).ready(function() {
      var slider = $('.component.usn_cmp_banner .slides, .swp .slides').slick({
        rtl: rtl_slick(),
                infinite: true,
                speed: 600,
                fade: true,
                adaptiveHeight: true,
                pauseOnFocus: false,
                prevArrow: '<div class="slick-prev"><i class="icon usn_ion-ios-arrow-back"></i>',
                nextArrow: '<div class="slick-next"><i class="icon usn_ion-ios-arrow-forward"></i>'
      });
      slider.on('afterChange', function(event, slick, currentSlide) {
        var vid = $(slick.$slides[currentSlide]).find('iframe');
        if (vid.length > 0) {
          slider.slick('slickPause');
          $(vid).get(0).play();
        }
      });
    
      $('iframe').on('ended', function() {
        console.log('Video Complete')
        slider.slick('slickPlay');
      });
    });
    
  • Stephen Barr 2 posts 73 karma points
    Dec 11, 2020 @ 07:56
    Stephen Barr
    0

    Hi,

    I think you need to target both the current slide and also the next slide. Looking back on something I did previously, you might be able to apply it to your scenario. In my case, as each slide changed, I was changing the style of the navigation, for example, on one slide the navigation might be black and then on the next slide the navigation colour would change to white, therefore before each change I was removing a class (this is where you would stop the video), and then I would add the new class to the next slide (in your case playing the next video)

            $('.sliders').on('beforeChange', function (event, slick, currentSlide, nextSlide) {
    
            var current = $(slick.$slides[currentSlide]);
            var currentBranding = current.data('branding');
            var next = $(slick.$slides[nextSlide]);
            var nextBranding = next.data('branding');
            $('.navigation').removeClass(currentBranding);
            $('.navigation').addClass(nextBranding);
    
    
        });
    

    Hope this helps in some way.

Please Sign in or register to post replies

Write your reply to:

Draft