YouTube API似乎不会在Firefox中加载,IFrame被加载,但onPlayerReady事件永远不会触发? [英] YouTube API does not appear to load in Firefox, IFrame gets loaded , but the onPlayerReady event never fires?

查看:737
本文介绍了YouTube API似乎不会在Firefox中加载,IFrame被加载,但onPlayerReady事件永远不会触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加载YouTube播放器API如下:

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


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

在chrome上,IFrame就绪和玩家就绪事件被解雇, Firefox,只有iframe准备好了,我从来没有看到onPlayerReady事件触发。

我想知道这个问题的可能原因是什么,以及是否有是一种解决方法。我无法访问播放器的功能,如loadPlaylist由于这个问题。

谢谢

解决方案

就我而言,易卜拉欣引用的答案并不是我所面临的问题。



我的视频是在一个以 display:none 开头的模式窗口中加载的, code>就可以了。这阻止了Firefox完全处理API,并且随后 onReady 事件没有被触发。 Safari和Chrome的行为如预期,没有任何错误可言,所以这让我挠了脑袋太久。



我改变了 display:none to visibility:hidden ,并且事件被解雇了,一切都很顺利。



我通过这个答案告知了这个。



编辑:



即使在上述修复程序之后,Internet Explorer 10和11也有同样的问题。对这篇文章的第一个评论让我简单地使用了定位(即。 left:-150% )隐藏和显示我的模式,而不是可见性显示属性。奇怪的是,禁用Flash也解决了这个问题,但这显然不是一个可行的解决方案...

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

解决方案

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 comment 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…

这篇关于YouTube API似乎不会在Firefox中加载,IFrame被加载,但onPlayerReady事件永远不会触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆