1

Im using Owl Carousel 2.0.0-beta.2.4 and in one slide I have a HTML5 video. What I want to do is when I change slide I want the video to be paused or stopped if pause is not possible. The slide can be changed by drag, touch, next and prev buttons and by keyboard arrows.

My script looks like this right now:

$('.owl-carousel').owlCarousel({
    items: 1,
    animateOut: 'fadeOut',
    animateIn: 'fadeIn',
    URLhashListener: true,
    startPosition: 'URLHash',
    nav: true,
    autoHeight : true,
    video:true,
});

var owl = $('.owl-carousel').data('owlCarousel');

$(document.documentElement).keyup(function(event) {
    if (event.keyCode == 37) {
        owl.prev();
    } else if (event.keyCode == 39) {
        owl.next();
    }
});  

I have heard about onMove or callback functions but I don't quite understand them.

Henric Åkesson
  • 140
  • 1
  • 2
  • 11

2 Answers2

2

I solved it with this code:

        onTranslate: function() {
        $('.owl-item').find('video').each(function() {
            this.pause();
        });
    }

So final code for my owl-carousel is:

    $('.owl-carousel').owlCarousel({
    items: 1,
    animateOut: 'fadeOut',
    animateIn: 'fadeIn',
    URLhashListener: true,
    startPosition: 'URLHash',
    nav: true,
    autoHeight: true,
    video: true,
    responsiveRefreshRate: 100,
    onTranslate: function() {
        $('.owl-item').find('video').each(function() {
            this.pause();
        });
    }
});
Henric Åkesson
  • 140
  • 1
  • 2
  • 11
  • This doesn't seem to work on the latest Owl Carousel 2 :/ I think because they changed how they handle video – ckhatton Jan 11 '17 at 10:35
  • I went for the brutal approach, which is to kill the iframe `$('SELECTOR iframe').prop('src','')` ([source](http://stackoverflow.com/questions/6145990/how-to-stop-a-vimeo-video-with-jquery)) – ckhatton Jan 11 '17 at 10:58
0

Check out the doc: http://www.owlcarousel.owlgraphic.com/docs/api-events.html

owl.on('changed.owl.carousel', function(event) {
    $(".owl-carousel video").get(0).pause();
})
mika
  • 1,411
  • 1
  • 12
  • 23
  • I have tried that. That does not make it work. What I want is to pause my HTML5 video when I change slide by keyboard, dragg, touch or select next or prev slide by navigation. – Henric Åkesson Feb 06 '15 at 22:42
  • You'll need to listen to the proper events, and to find out you will need to read the doc. – mika Feb 07 '15 at 16:03