我正在使用Youtube JavaScript API和swfobject来嵌入视频,onYouTubePlayerReady
永远不会被调用。这是怎么回事?这是我的代码:
<div id="ytapiplayer">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>
<script>
// Inject YouTube API script
var tag = document.createElement('script');
tag.src = '//www.youtube.com/player_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var VIDEO_ID='<?php echo $video_id; ?>';
var params = {
'allowFullScreen': 'true',
'allowScriptAccess': 'always',
'allownetworking': 'internal'
};
var atts = {
'class': 'bilingual-video',
'id': 'ytapiplayer'
};
swfobject.embedSWF(
'http://www.youtube.com/v/' +
VIDEO_ID +
'?enablejsapi=1&playerapiid=ytapiplayer&version=3' +
'&showinfo=0&modestbranding=1&controls=0',
'ytapiplayer', '500', '400', '8', null, null, params, atts);
</script>
<script>
var ytplayer;
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById('ytapiplayer');
};
</script>
答案 0 :(得分:1)
您已将allownetworking
设置为“内部”;根据定义,这不允许SWF通过Flash的ExternalInterface
API与任何内容进行通信。但是,YouTube javascript API依赖于ExternalInterface,因此实际上您已阻止了SWF对API的访问。
如果删除该参数,它应该再次开始调用onYouTubePlayerReady
函数。