<html>
<body>
<div id="ytplayer_div1">You need Flash player 8 or higher to view this content.</div>
<script type='text/javascript' src='swfobject.js'> </script>
<script type='text/javascript'>
swfobject.embedSWF
(
'http://www.youtube.com/apiplayer?enablejsapi=1',
'ytplayer_div1',
'425',
'344',
'8',
null,
null,
{
allowScriptAccess: 'always',
allowFullScreen: 'true'
},
{
id: 'ytplayer_object'
}
);
var ytplayer = document.getElementById("ytplayer_div1");
ytplayer.loadVideoById("bHQqvYy5KYo", 5, "large");
</script>
</body>
</html>
答案 0 :(得分:1)
来自YouTube Javascript Player API: Getting Started,
当播放器准备就绪时,API将调用
onYouTubePlayerReady
回调函数。
裹
var ytplayer = document.getElementById("ytplayer_div1");
ytplayer.loadVideoById("bHQqvYy5KYo", 5, "large");
与
onYouTubePlayerReady = function() {
var ytplayer = document.getElementById("ytplayer_object");
ytplayer.loadVideoById("bHQqvYy5KYo", 5, "large");
}
请注意document.getElementById("ytplayer_object")
,其中 id 必须等于传递到swfobject.embedSWF
的 id 属性:
{
id: 'ytplayer_object'
}