2015-06-05 79 views
1

我正在加載YouTube播放器API,如下所示 我試圖觸發一個事件,當我播放到我的fancybox中的youtube視頻結束後,顯示一個彈出窗口。YouTube onPlayerStateChange未開火

我發現和嘗試,但事件不點火

<!doctype html> 
<html lang="en"> 
<body> 
<a class="fancybox fancybox.iframe" id="vdo" href="http://www.youtube.com/embed?listType=playlist&list=PL590L5WQmH8f_0qlZ-tKrtbfw4n0jyHQ">Video #1</a> 


<script> 
// Fires whenever a player has finished loading 
function onPlayerReady(event) { 
    event.target.playVideo(); 
} 

// Fires when the player's state changes. 
count = 0; 
     function onPlayerStateChange(event) { 
      if(event.data == 0) 
      { 
       count++; 
      }   
      if(count == 6) 
      { 
       $("#popup-wrapper-center").show(); 
      } 
     } 

// The API will call this function when the page has finished downloading the JavaScript for the player API 
function onYouTubePlayerAPIReady() { 

    // Initialise the fancyBox after the DOM is loaded 
    $(document).ready(function() { 
     $(".fancybox") 
      .attr('rel', 'gallery') 
      .fancybox({ 
       openEffect : 'none', 
       closeEffect : 'none', 
       nextEffect : 'none', 
       prevEffect : 'none', 
       padding  : 0, 
       margin  : 50, 
       beforeShow : function() { 
        // Find the iframe ID 
        var id = $.fancybox.inner.find('iframe').attr('id'); 

        // Create video player object and add event listeners 
        var player = new YT.Player(id, { 
         events: { 

          'onStateChange': onPlayerStateChange 
         } 
        }); 
       } 
      }); 


    }); 

} 
</script> 
</body> 
</html> 
+0

http://stackoverflow.com/questions/14880803/fancybox-and- YouTube的-API事件 – Ellis

回答

1

更改ID,視頻,而不是VDO代碼