Youtube播放器未在IE 8和IE 10中触发onReady和onStateChange事件

时间:2013-01-31 09:59:42

标签: events youtube

我花了3天时间试图解决这个问题。很快,Youtube播放器不会在IE8和IE10中触发onReady和onStateChange事件。我在Firefox上进行了测试,但它确实有效。基本上,我正在开发一个使用WebView来托管html的Windows 8 metro应用程序,但它在WebView中也不起作用。

视频加载和onYouTubeIframeAPIReady被调用,但这就是它。下面是html代码。

onPlayerReady和onPlayerStateChange函数中的警报消息不会显示在IE8和IE10中,但会显示在Firefox中。

请帮助.....

<!DOCTYPE html> 
<html> 
<body> 
<div id="player"></div> 
<script> 

alert('LOADING');
alert(GetUserAgent());

var tag = document.createElement('script');
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

var player;
function onYouTubeIframeAPIReady() 
{ player = new YT.Player('player', { height: '315', width: '560',
 videoId: 'CreKbwMTZA8', playerVars: {'autoplay': 1}, 
events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange }  });  
alert('onYouTubeIframeAPIReady');
}

function onPlayerReady(event) 
{ 
event.target.playVideo(); 
alert('onPlayerReady');
}

function onPlayerStateChange(event) 
{
alert('onPlayerStateChange');

if (event.data == YT.PlayerState.PLAYING) { window.external.notify('PLAYING');}
else if (event.data == YT.PlayerState.ENDED) {window.external.notify('ENDED');}
}

function setSize(width, height) 
{ player.setSize(width, height); 
}

function GetUserAgent() 
{
  return navigator.userAgent;
}

</script>
</body>
</html>

0 个答案:

没有答案