回答

0

看看我的功能定義在這個答案:Listening for Youtube Event in JavaScript or jQuery

在你的情況下,實現的核心功能,如下所示(小提琴:http://jsfiddle.net/w2w5x/

// Core functions defined at https://stackoverflow.com/q/7988536#7988536 
var player; 
YT_ready(function(){ 
    var frameID = getFrameID("YOUR-frame-or-container-ID-here"); 
    if (frameID) { //If the frame exists 
     player = new YT.Player(frameID, { 
      events: { 
       "onStateChange": function(event){ 
        if(event.data == "0") { 
         //The video has finished 
         alert("The video has finished!"); 
         //Do something, example: play again 
         player.playVideo(); 
        } 
       } 
      } 
     }); 
    } 
});