直到两周前,我的一切都很好。我没有更改任何代码。
function loadYtVideo(video, advert, advert_link, splash, splash_link){
var params = { allowScriptAccess: "always", wmode: "transparent" };
var atts = { id: "eda-player", wmode: "transparent" };
var swfobject;
adv.orig = video;
swfobject.embedSWF("https://www.youtube.com/v/"+adv.orig+"?rel=0&enablejsapi=1&playerapiid=ytplayer","ytapiplayer", "719", "404", "8", null, null, params, atts);
}
function onYouTubePlayerReady(playerId) {
//It's fired
edaplayer = document.getElementById('eda-player');
edaplayer.addEventListener("onStateChange", "playerState");
}
function playerState(state) {
//it's not fired
console.log(state);
}
<div class="adv-video">
<div id="ytapiplayer">
<script>
$(document).ready(function(){
loadYtVideo($.getUrlVar('ytVideo'), 'eM2ja9LE0YE', 'http://wilmax.ru/', '', '');
});
</script>
</div>
</div>
我发现有类似问题的帖子,但在这些帖子中的解决方案在这种情况下不起作用。
我建议你移动到YouTube IFrame Player API:
Flash API和JS API已经被弃用。我不确定它是否仍然与当前的API工作,这就是为什么我建议你使用Iframe APIIFrame播放器API允许您在您的网站上嵌入YouTube视频播放器,并使用JavaScript控制播放器。与Flash和JavaScript播放器API不同,它们都涉及在网页上嵌入Flash对象,IFrame API将内容发布到页面上的
<iframe>
标签。这种方法提供了比以前可用的api更大的灵活性,因为它允许YouTube为不支持Flash的移动设备提供HTML5播放器而不是Flash播放器。
这里有一些可能对你有帮助的来源:
- JS Fiddle Demo 嵌入Flash
- 相关问题
希望这对你有帮助!