最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - YouTube API does not appear to load in Firefox, IFrame gets loaded , but the onPlayerReady event never fires? - Sta

programmeradmin0浏览0评论

I am loading the YouTube player API as follows:

      var player;
  function onYouTubeIframeAPIReady() {
console.log("iframe ready");
    player = new YT.Player('player', {
      height: '390',
      width: '640',
      events: {
        'onReady': onPlayerReady,
        'onStateChange': onPlayerStateChange
      }
    });
  }


function onPlayerReady(){
console.log("player ready");
}

On chrome both the IFrame ready and the player ready events get fired, but on Firefox, only the iframe ready gets fired, and I never see the onPlayerReady event fire.

I was wondering what the possible causes of this issue are, and whether or not there is a workaround. I am unable to access player functions such as loadPlaylist due to this issue.

Thanks

I am loading the YouTube player API as follows:

      var player;
  function onYouTubeIframeAPIReady() {
console.log("iframe ready");
    player = new YT.Player('player', {
      height: '390',
      width: '640',
      events: {
        'onReady': onPlayerReady,
        'onStateChange': onPlayerStateChange
      }
    });
  }


function onPlayerReady(){
console.log("player ready");
}

On chrome both the IFrame ready and the player ready events get fired, but on Firefox, only the iframe ready gets fired, and I never see the onPlayerReady event fire.

I was wondering what the possible causes of this issue are, and whether or not there is a workaround. I am unable to access player functions such as loadPlaylist due to this issue.

Thanks

Share Improve this question edited Jan 4, 2014 at 23:28 Louis93 3,9219 gold badges53 silver badges94 bronze badges asked Jan 4, 2014 at 23:25 mlikj2006mlikj2006 1911 silver badge11 bronze badges 2
  • I am experiencing same problems on Chrome. Is this problem on Google side? – Gapipro Commented Jan 10, 2014 at 15:57
  • Your answer is here: stackoverflow./questions/17078094/… – Ibrahim Ulukaya Commented Jan 15, 2014 at 19:43
Add a ment  | 

2 Answers 2

Reset to default 7

In my case, the answer referenced by Ibrahim was not the issue I was facing. That's an older bug which looks to be resolved now anyways.

My video was loading in a modal window which starts out with display:none on it. This was preventing Firefox from fully processing the API and, and subsequently the onReady event wasn't firing. Safari and Chrome were behaving as expected and there were no errors to speak of so this left me scratching my head for way too long.

I changed display:none to visibility:hidden and the event fired and all was well with the world.

I was tipped off to this by this answer.

EDIT:

Internet Explorer 10 and 11 were having the same issue even after the fix mentioned above. The first ment on this post led me to simply use positioning (ie. left:-150%) to hide and show my modal, and not visibility or display attributes. Oddly enough, disabling Flash also fixed this but that's obviously not a workable solution…

Well there is also a problem with YT flash player. But when you use HTML5 player version all YT player var and all API methods are working just fine:

var player;
  function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
      height: '390',
      width: '640',
      videoId: 'M7lc1UVf-VE',
      playerVars: {
        html5: 1
      },
      events: {
        'onReady': onPlayerReady,
        'onStateChange': onPlayerStateChange
      }
    });
  }

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论