flickity icon indicating copy to clipboard operation
flickity copied to clipboard

html5 video slider

Open kukac7 opened this issue 9 years ago • 21 comments

Hi,

Does not work well with the slider cell with html5 video content.

look: http://codepen.io/kukac7/pen/ogMpNB

What could be the problem?

Thank you!

kukac7 avatar Mar 04 '15 11:03 kukac7

Adding proper support and documentation for HTML5 video is something I still need to do.

But I may have found a short-term solution. See demo CodePen: http://codepen.io/desandro/pen/PwBEgL or vanilla JS CodePen: http://codepen.io/desandro/pen/MYBQbp

$(document).ready( function() {
  var $gallery = $('.gallery').flickity();

  function onLoadeddata( event ) {
    var cell = $gallery.flickity( 'getParentCell', event.target );
    $gallery.flickity( 'cellSizeChange', cell && cell.element );
  }

  $gallery.find('video').each( function( i, video ) {
    video.play();
    $( video ).on( 'loadeddata', onLoadeddata );
  });

});

There are two issues to resolve

  1. imagesLoaded does not work with video. This demo adds an event listener to resize cells once its size is set, similar to imagesLoaded.
  2. WebKit has a bug where changing the DOM stops autoplay. This demo adds .play() to resume autoplay.

desandro avatar Mar 04 '15 14:03 desandro

thank you! :dancers:

kukac7 avatar Mar 04 '15 15:03 kukac7

Hi,

I am also interested and excited to see the support of html5 videos :)

dev4q1 avatar Mar 23 '15 14:03 dev4q1

+1

dcinzona avatar Apr 07 '15 12:04 dcinzona

+1! Would be nice to mix video and image.

christinechaochao avatar Jul 30 '15 05:07 christinechaochao

Is there a way to autoplay the carousel when the video is finished playing? I tried setting the autoplay variable to the duration of the video, but nothing moves when the video is finished playing. In fact, even if I set a static autoplay, it still does not auto play.

npredey avatar Aug 11 '16 14:08 npredey

@npredey I imagine you want trigger next then playPlayer

desandro avatar Aug 11 '16 19:08 desandro

yessss +1

coolwebs avatar Jan 21 '17 00:01 coolwebs

+1

stefanedberg avatar Feb 07 '17 14:02 stefanedberg

+1....million

bryanchalker avatar Mar 16 '17 02:03 bryanchalker

+1

dejardine avatar Jun 15 '17 21:06 dejardine

is this working for anyone? Im trying to get html5 video to play when the slide is in view, pause when user slides to new slide.

The demos above are not working!

HandHugs avatar Jul 27 '17 00:07 HandHugs

I have video categories in my website... How would I add the the categories to the Flickity slider??? A category such as "travel-and-event". How would I add or pull the video element into the slider, what functions would I use???

This is an example category: http://www.vtubemobi.com/cat/travel-and-event

tdcpepsi avatar Oct 27 '17 21:10 tdcpepsi

Indeed, I can't get those demos to work, and was really hoping to use Flickity on a current project.

brigleb avatar Nov 03 '17 13:11 brigleb

yes same here.... to bad

ianhobbs avatar Dec 05 '17 00:12 ianhobbs

So there's no way to make a html 5video slider with Flickity? I made one, but when you slide it to the next one, the video start.... any idea?!

jmharveys avatar Mar 07 '18 19:03 jmharveys

??

jmharveys avatar Mar 08 '18 14:03 jmharveys

I got it working eventually with this

this.$slideshow.on( 'cellSelect.flickity', function() {
       $('.slideshow-slide').find('video').get(0).pause();
        $('.is-selected').find('video').get(0).play();
       
      });

HandHugs avatar Mar 08 '18 20:03 HandHugs

var playWholeVideo = true;
				$(this).flickity({
						prevNextButtons: false,
						pageDots: false,
						cellSelector: '.coverItem',
						draggable: false,
						freeScroll: false,
						wrapAround: true,
						autoPlay: false,
						pauseAutoPlayOnHover: false,
						imagesLoaded: true,
						on: {
							select: function (index) {
								var flkty = this;
								$(flkty.selectedElement).find('video').each(function (i, video) {
									if (playWholeVideo) {
										flkty.stopPlayer();
										video.loop = false;
										video.onended = function (e, i) {
											flkty.next();
										};
									}
									video.play();
								});
							},
							change: function (index) {
								if (!playWholeVideo) {
									var flkty = this;
									var previousIndex = index === 0 ? flkty.slides.length - 1 : index - 1;
									var previousElement = flkty.slides[previousIndex].getCellElements();
									$(previousElement).find('video').each(function (i, video) {
										video.pause();
									});
								}
							}
						}

salunet avatar Oct 30 '18 16:10 salunet

Could this work with masonry? and if yes, how would it.

riddy92 avatar Sep 07 '19 17:09 riddy92

Could this work with masonry? and if yes, how would it.

Yeap, easy:

// init Masonry
var $grid = $('.grid').masonry({
  // options...
});

//call when element loaded
function onLoaded( event ) {
  $grid.masonry('layout')
}

// layout Masonry after each image loads
$grid.imagesLoaded().progress(onLoaded);

//*****//-VIDEO LOAD-//*****//

// layout Masonry after each video loads
$grid.find('video').each( function( i, video ) {
  $( video ).on( 'loadeddata', onLoaded );
});

//*****//-//*****//-//*****//

nnmbzr avatar Dec 08 '22 16:12 nnmbzr