-1

我正在测试 Youtube API,但状态监听器在演示中不起作用,我不明白为什么?

这是演示的简单代码:

    <script src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" type="text/javascript"></script>
<script type="text/javascript">
    var params = { allowScriptAccess: "always" };
    var atts = { id: "myytplayer" };
    swfobject.embedSWF("http://www.youtube.com/v/u1zgFlCw8Aw?enablejsapi=1&playerapiid=ytplayer&version=3",
                       "ytapiplayer", "425", "356", "8", null, null, params, atts);
    function onYouTubePlayerReady(playerId) {
      ytplayer = document.getElementById("myytplayer");
      ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
    }
    function onytplayerStateChange(newState) {
       alert("Player's new state: " + newState);
    }
</script><div id="ytapiplayer">
You need Flash player 8+ and JavaScript enabled to view this video.  </div>
4

1 回答 1

1

你是在本地电脑上测试吗?

尝试在网站上测试并使用前缀 http:// 访问它

编辑: 你已经解决了。不好意思,发帖后才知道。

于 2012-06-19T07:48:03.380 回答