Youtube iframe api: 'onReady', 'onStat

2019-07-19 07:57发布

问题:

I just was checking my youtube player in IE 8 and noticed the 'onReady', 'onStateChange' events are not firing. The initPlayer method is being called and the video plays, but the events are not firing.

Works as expected on Safari, Firefox Mac, FireFox Win.

Am I missing something here?

Here is the relevant code:

MyPlayer.prototype = {

/*   [...]  */


initPlayer: function () {

    var that = this;
    alert("initPlayer: (IE 8 gets this far)");

    this.player = new YT.Player(this.cfg.divTagId, {
        height:  this.cfg.height,
        width:   this.cfg.width,
        videoId: this.cfg.videoId,
        origin:  location.host,
        playerVars: {
           controls: this.cfg.controls, 
           wmode: 'opaque',
          fs: 0
       },
       events: {
         'onReady': function (event) {alert("onReady")},
         'onStateChange': function (event) {alert("onChange")}
      }
   });

},

/* [...] */

}

回答1:

This was an old bug in the YouTube api code. It should all be working at this point.



回答2:

One possible factor: the API won't work properly in IE if you are running it locally - try running your code from an http: path.

Source:

http://groups.google.com/forum/?fromgroups=#!topic/youtube-api-gdata/LV49fIR5Uo0



标签: youtube-api