我已经对这个问题进行了几个小时的故障排除和搜索,但都没有结果。API文档中的示例代码是逐字使用的。其他人说在IE9上可以工作的示例代码对我来说不是这样的。我已经确认文档类型在html中设置正确,我没有在CSS中使用display=none隐藏iframe,浏览器模式是IE9,文档模式是IE9标准。我的安全设置配置为中高。即使是谷歌的示例页面在我的IE9浏览器中也不能正常工作。
https://developers.google.com/youtube/youtube_player_demo
当我点击“播放”来尝试播放电影(在上面的链接中)时,我在IE的脚本调试控制台中得到了各种错误。第一个错误如下所示:
视频:‘SCRIPT5009’未定义
请帮帮我!我的示例代码如下。电影加载,我看到"API is ready“警报,但其他事件都不会在IE9中触发。我只是不知道我错过了什么!如果我不尽快解决这个问题,我将不得不放弃在我的项目中为html5视频回放使用YouTube。
<!DOCTYPE html>
<html>
<head><title></title></head>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script type="text/javascript">
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
// This is a protocol-relative URL as described here:
// http://paulirish.com/2010/the-protocol-relative-url/
// If you're testing a local page accessed via a file:/// URL, please set tag.src to
// "https://www.youtube.com/iframe_api" instead.
//tag.src = "//www.youtube.com/iframe_api";
tag.src = "https://www.youtube.com/iframe_api";
//tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
alert("API is ready!");
player = new YT.Player('player', {
height: '450',
width: '800',
videoId: 'mU7aJgvh9K8',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
alert("Player is ready!");
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
alert("State changed!");
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
</body>
</html>发布于 2013-03-08 22:53:20
嗯,在同事的机器上测试后,我意识到问题是我系统上的IE造成的,于是我又开始查看浏览器设置。心血来潮之下,我关掉了我的Flash播放器(在“互联网选项”->“程序”->“管理插件”下)和中提琴,视频代码运行得很棒。我还注意到我的Flash播放器已经过时了(9.0.45.0),在安装了最新版本的播放器后,它仍然可以工作。
我不知道为什么旧的YouTube播放器会干扰Flash和事件--但这显然是罪魁祸首。
https://stackoverflow.com/questions/15230279
复制相似问题