- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我复制了Youtube内嵌播放器的演示代码Youtube embedded player demo code几乎一字不差 - 更改是插入 console.log 以便我可以看到发生了什么。
<!DOCTYPE html>
<html>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://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() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
console.log('onPlayerReady');
event.target.playVideo();
}
// 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) {
console.log('onPlayerStateChange');
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
</body>
</html>
这在 Safari 和 Firefox 中按预期工作,即一旦 API 加载选择的视频播放 6 秒并且 console.log 包含事件正在触发的证据。但是在 Internet Explorer 中,onReady 和 onStateChange 事件不会触发。如果我手动单击播放器中的播放控件,视频将播放,但我没有收到预期的 onStateChange 事件。
我检查了我机器上的 Flash 版本,它是:11.2.202.228,当前可用的是 12.0.0.70。如果我在 IE 中禁用 Flash(管理附加组件),播放器将按预期工作:播放 6 秒并触发事件。
我没有更新 Flash,因为虽然这可能会解决我机器上的问题,但我的观众将仅限于那些可以做同样事情的人,如果我更新了,我将无法确定问题是否已被其他人解决意味着。
我也曾尝试自己手动创建 iframe,如上述 Youtube 文档中所述,这在 Firefox 和 Safari 中按预期工作但在 IE 中没有。
有一个Youtube demo player 这在 Firefox 中完美运行,通过 API 工作的播放、暂停和停止控件以及事件在“统计”部分的屏幕上写入事件和函数调用时清楚地触发。相比之下,当我在 IE 中查看此内容时,通过 API 进行的播放、暂停和停止控件什么都不做。统计部分没有输出。播放和暂停的唯一方法是使用播放器上的按钮。如果我禁用 Flash,那么播放器和 API 将完美运行。
如果我尝试嵌入非 API 的 iframe,那么播放器可以正常工作,这让我相信这是使用 API 引起的问题。
我知道有些人会说所有用户都应该拥有最新的 Flash,说起来容易做起来难。许多学校、公司和图书馆都锁定了 IE 中的选项部分,以便用户能够为我的网站关闭 Flash。
我想知道在使用 API 时有什么方法可以关闭 Flash 吗?
我在 Stackoverflow 和其他地方进行了搜索,虽然我发现了类似的问题,但我没有找到任何修复方法。 I did find a somewhat similar promising lead但唉,我没有快乐。 Also here和 here和 here和 here和 here .
我必须指出,在本地机器和网站上使用时,即使我设置了 origin 参数,问题仍然存在。
我将不胜感激建议和帮助。提前致谢。
最佳答案
I wonder is there some way of turning off Flash when using the API?
您可以使用以下选项强制 YouTube 播放器使用其 html5 播放器:
playerVars: {html5: 1}
将您的代码更改为:
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
playerVars: {
html5: 1
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
关于javascript - Youtube 嵌入式 iframe onReady 和 onStateChange 事件未在 Internet Explorer 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22227737/
直到大约两周前,我一切都运转良好。我没有更改任何代码。 function loadYtVideo(video, advert, advert_link, splash, splash_link){
当您更改 YouTube 视频 ID 时,相同代码的行为会有所不同。 问题是,当您拉动进度 slider 时,它会在一个视频上触发 onStateChange 事件,但不会在另一个视频上触发。检查下面
player = new YT.Player(A, { videoId: z.videoId, height: z.he
我遇到了 YouTube 播放器 OnStateChange 未触发的问题。我看过其他帖子,它们不太适合我的情况,因为我可能使用不同的(chromeless javascript)版本。 HTML:
我有一个 iframe,可以在开始时间和结束时间之间播放视频。当到达结束时间时(case 0),我想加载几乎相同的 URL(在 autoplay=0 处有所不同)。 问题是 OnStateChange
我正在为 Chrome 构建一个笔记应用程序,我希望该应用程序在用户停止输入时保存其进度,但我无法让 chrome.idle 触发状态更改 chrome.idle.setDetectionInterv
引用问题:http://jsfiddle.net/yusaf/VVEY9/55/ 当视频播放器状态发生变化时 onStateChange(0) 即视频结束时,我将如何隐藏 .pause 元素并添加一个
我在我的应用程序中使用了 atmosphere 框架。 https://github.com/Atmosphere/atmosphere 我扩展了 AbstractReflectorAtmospher
在Flutter中,有没有像onStateChanged这样的方法,在页面状态发生变化时调用? setState(() { widget._loadCompleted = true; widg
我只是一个js初学者,所以可能我只是理解不正确。但是,当您之前使用 History.stateObj 更改状态时,当您点击浏览器的后退/前进按钮时,window.onstatechange 不应该触发
我想使用 Youtube API 提供的 onStateChange 事件来收听视频的结尾,然后在播放器中播放一个新视频。但是,由于某种原因,这似乎是不可能的。 function onPlayerSt
我正在使用 Youtube iFrame API 开发一个小应用程序,让您可以与其他人同步观看视频。 onStateChange 事件让我知道播放器是否播放或暂停了视频,但它是否包含有关该操作是否通过
我的javascript: function onYouTubePlayerReady() { playerObj = document.getElementById("player_embed"
请告诉我我哪里做错了。 我使用的是 History.js HTML5 版本。当我的网址类似于 example.com/?param=1 我把它改成 example.com/?param=2 使用 Hi
我有两个 colorbox 弹出框,每个框都显示一个 YouTube 视频。当他们玩完后,我试图让他们自动关闭 colorbox 窗口。下面的代码在 Firefox 中完美运行,但在 IE 中我无法使
我正在使用 iframe YouTube API,我想跟踪事件,例如,在用户开始和停止视频时将数据发送到谷歌分析。 我看了https://developers.google.com/youtube/
这个问题在这里已经有了答案: YouTube iframe player API - OnStateChange not firing (2 个回答) 7年前关闭。 直到美国东部标准时间下午 6 点左
这个问题已经有答案了: YouTube iFrame API 'onStateChange' not firing in Firefox (1 个回答) 已关闭 9 年前。 我只是想在 YouTube
我正在用 C++ 开发 Firefox 扩展我想获取我已为 STATE_IS_NETWORK 获得 STATE_STOP 的选项卡窗口的选项卡索引。即我想找到与请求关联的选项卡索引。 如何获取? 请帮
我集成了 History.js,这段代码在 URL 更改时运行: History.Adapter.bind(window,'statechange',function(){ var State
我是一名优秀的程序员,十分优秀!