I'm trying to create a Swiper slider with YT videos and html5 videos. I have the YT videos working however I just can't get the HTML 5 videos to work. I'm having trouble to detect the progress of the video. Whatever I try I just can't keep track of when the video ends so I can jump to the next slide.
So what I have is just 1 video to test now:
window.addEventListener('load', function() {
.....
swiper = new Swiper('#headlines .swiper-container', {
.... settings .....
});
if(is_video){
var sliderVideos = $(".swiper-slide video");
swiper.on('init', function() {
var currentVideo = $("[data-swiper-slide-index=" + this.realIndex + "]").find("video");
currentVideo.trigger('play');
console.log('video plays')
currentVideo.on('ended', function(){
console.log('video ended')
swiper.autoplay.start()
swiper.slideNext();
});
});
swiper.on('slideChange', function () {
sliderVideos.each(function( index ) {
this.currentTime = 0;
});
var prevVideo = $("[data-swiper-slide-index=" + this.previousIndex + "]").find("video");
prevVideo.trigger('stop');
});
}
swiper.init();
});
I also tried
video.addEventListener("ended", function() {
console.log('Video has ended!');
});
Or
currentVideo.bind('ended', function(){
console.log('Video has ended!');
});
I just can't see what I'm doing wrong.