jquery - Videos within a Twitter Bootstrap carousel, doesn't stop playing -


using latest version of twitter bootstrap, , embedding vimeo videos through iframe... built simple carousel of bootsnipp (extend carousel) , rather placing image thumbnails, i've added videos. however, i've run problem where... when play first video , click on video, first keeps playing. need stop videos when video clicked.

many other post deal youtube , ones i've seen vimeo don't seem help.

i haven't used bootsnipp, following works vanilla bootstrap.

you need use vimeo javascript api manually pause video when bootstrap carousel slides next slide. simplest using vimeo's froogaloop library.

give each vimeo player <iframe> unique id, pass id "player_id", add listener bootstrap's "slide.bs.carousel" event (in bootstrap v3.0; believe "slide" in v2.3.2), , call froogaloop.api("pause") on corresponding vimeo player.

when creating vimeo slides in carousel, each vimeo player should follow basic setup (for clarity, i'm not including options / attributes other id , src; note api=1 required query variable in src attribute activate vimeo javascript api):

<iframe id="player-id-n" src="http://player.vimeo.com/video/yourvideoidhere?player_id=player-id-n&api=1"></iframe> 

(where n unique id, possibly iterator index.)

(edit: the <iframe> id , player_id not necessary technique, still useful depending on setup.)

once carousel created, bind handler slide event:

$mycarousel.on("slide.bs.carousel", function (event) {     // bootstrap carousel marks current slide (the 1 we're exiting) 'active' class     var $currentslide = $mycarousel.find(".active iframe");      // exit if there's no iframe, i.e. if image , not video player     if (!$currentslide.length) { return; }      // pass iframe froogaloop, , call api("pause") on it.     var player = froogaloop($currentslide[0]);     player.api("pause");  }); 

here's working jsfiddle doesn't use <iframe> id or player_id, mentioned in edit above.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -