为什么视频没有加载?我应该如何在无边框播放器上加载和播放视频?

时间:2013-04-26 12:43:08

标签: youtube-api youtube-javascript-api

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

1 个答案:

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