<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>
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'
}