0
 <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>
4

1 回答 1

1

来自YouTube Javascript Player API:入门

当播放器准备好时,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必须等于传入此处的idswfobject.embedSWF属性:

{
    id: 'ytplayer_object'
}
于 2013-04-26T13:41:08.003 回答