我正在测试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>
答案 0 :(得分:1)
您是否在本地计算机上进行测试?
尝试在网站上进行测试并使用前缀http://
进行访问修改强> 你已经解决了。对不起,发布后我才意识到。