根据我的阅读,这就是我应该如何设置 YouTube应用程序接口(interface):
<!DOCTYPE html>
<html lang="en">
<head>
<meta content='text/html;charset=UTF-8' http-equiv='content-type' />
<title>Youtube Player</title>
<script src="jquery.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
function onYouTubePlayerReady(id) {
console.log("onYouTubePlayerReady() Fired!");
var player = $("#youtube_player").get(0);
}
var params = { allowScriptAccess: "always" };
var atts = { id: "youtube_player" };
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1",
"youtube", "425", "356", "8", null, null, params, atts);
</script>
</head>
<body>
<div id="youtube"></div>
</body>
</html>
但是,'onYouTubePlayerReady()' 根本不会触发,如果我手动获取对播放器的引用,很多方法都是未定义的;例如,cueVideoById() 有效,但 playVideo() 无效。
我该如何解决这个问题?
最佳答案
如 documentation 中所述,您需要使用测试脚本在 Web 服务器上:
Note: To test any of these calls, you must have your file running on a webserver, as the Flash player restricts calls between local files and the internet.
关于javascript - YouTube API — 未触发 'onYouTubePlayerReady()',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2083128/