title: Bootstrap carousel - pause when YouTube video played
body: <p>I have some embedded YouTube videos in my Bootstrap carousel.  By default, the carousel advances automatically, but I'd like to to pause when a video is playing.  </p>
  
  <p>Is there a trick to detecting when the video is playing?  I'd like to do it without using the YouTube API if possible (each carousel has an arbitrary number of videos, and I'd like not to create instances of every video).</p>
  
  <p><strong>Edit: Final Design</strong></p>
  
  <p>I created an overlap over the video:</p>
  
  <pre><code>.video_mask{
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:275px;
    z-index:25;
    opacity:0;
  }
  </code></pre>
  
  <p>When I click on the mask, I set the corresponding iframe to autoplay, hide the mask, and pause the carousel:</p>
  
  <pre><code> $('.video_mask').click(function(){
      iframe = $(this).closest('.item').find('iframe');
      iframe_source = iframe.attr('src');
      iframe_source = iframe_source + "?autoplay=1"
      iframe.attr('src', iframe_source);
      // hide the mask
      $(this).toggle();
      // stop the slideshow
      $('.projectOverviewCarousel').carousel('pause');
    });
  </code></pre>
  
  <p>When the user clicks on the carousel controls, it resets all masks and iframe urls:</p>
  
  <pre><code>  $('.projectOverviewCarousel').on('slide', function(){
      var iframeID = getID($(this).find('iframe').attr("id"));
      // stop iframe from playing
      if(iframeID != undefined){
        callPlayer(iframeID, 'stopVideo');
      }
      // turn on all masks
      $('.video_mask').show();
      // reset src of all videos
      $('.projectOverviewCarousel').find('iframe').each(function(key, value){
        url = $(this).attr('src');
        if(url.indexOf("autoplay")&gt;0){
          new_url = url.substring(0, url.indexOf("?"));
          $(this).attr('src', new_url);
        }
      });
  </code></pre>
  
  <p>Some things to check out for: make sure the controls for the bootstrap carousel have a z-index greater than the mask (so the person can still progress the slideshow manually).</p>
  
  <p>Hope this is useful to someone else!</p>