YouTube Iframe API - OnStateChange 突然不起作用 [英] YouTube Iframe API - OnStateChange suddenly not working

查看:30
本文介绍了YouTube Iframe API - OnStateChange 突然不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到美国东部标准时间下午 6 点左右,下面的代码都可以正常工作,但现在由于某种原因 onStateChange 没有触发.我在多个浏览器上尝试过,并让朋友检查过.看到什么明显的错误了吗?

<div id="player_wrap"><div id="玩家"></div>

<脚本>var tag = document.createElement("script");tag.src = "http://www.youtube.com/iframe_api";var firstScriptTag = document.getElementsByTagName("script")[0];firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);函数 onYouTubeIframeAPIReady() {var 播放器;玩家 = 新 YT.Player("玩家", {宽度:640,高度:400,videoId: "MbfsFR0s-_A",事件:{'onReady': onPlayerReady,'onStateChange': onPlayerStateChange}});}函数 onPlayerReady() {警报(玩家准备好");}函数 onPlayerStateChange(event) {警报(发生了一些事情");}

解决方案

这是 iFrame Player API 的临时问题.您可以在此处阅读:https://code.google.com/p/gdata-issues/issues/detail?id=4706

Jeff Posnick 在此处发布了一个临时解决方法:http://jsfiddle.net/jeffposnick/yhWsG/3/

基本上,您只需要在 onReady 事件中添加事件侦听器(只是临时修复):

function onReady() {player.addEventListener('onStateChange', function(e) {console.log('状态是:', e.data);});}

Until around 6pm EST this code below would have worked fine, but now for some reason onStateChange is not firing. I've tried on multiple browsers and have had friends check it. See anything obviously wrong?

<div id="video">
  <div id="player_wrap">
    <div id="player"></div>
  </div>
</div>

   <script>

    var tag = document.createElement("script");
    tag.src = "http://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName("script")[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

    function onYouTubeIframeAPIReady() {
    var player;

        player = new YT.Player("player", {
          width: 640,
          height: 400,
          videoId: "MbfsFR0s-_A",
          events: { 
            'onReady': onPlayerReady, 
            'onStateChange': onPlayerStateChange          
          }
        });
      }

function onPlayerReady() {

alert ("player ready"); 

}


function onPlayerStateChange(event) {

alert ("something happened"); 

}

解决方案

This is a temporary issue with the iFrame Player API. You can read about it here: https://code.google.com/p/gdata-issues/issues/detail?id=4706

Jeff Posnick posted a temporary workaround here: http://jsfiddle.net/jeffposnick/yhWsG/3/

Basically, you just need to add the event listener within the onReady event (just a temporary fix):

function onReady() {
    player.addEventListener('onStateChange', function(e) {
        console.log('State is:', e.data);
    });
}

这篇关于YouTube Iframe API - OnStateChange 突然不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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