Vimeo Froogaloop API 无法识别事件
我正在尝试使用 froogaloop API 识别 vimeo 的 onPlay、onPause 和 onFinish 事件。我已经尝试了所有我能想象到的东西,但没有运气。
我在 Firefox 上收到此错误:
在 Chrome 中:
从CDN:
<script src="http://a.vimeocdn.com/js/froogaloop2.min.js"></script>
我的 JS:
$(function(){
var vimeoPlayer = document.querySelector('iframe');
$f(vimeoPlayer).addEvent('ready', ready);
function ready(player_id) {
froogaloop = $f(player_id);
function setupEventListeners() {
function onPlay() {
froogaloop.addEvent('play',
function(data) {
console.log('play event');
});
}
function onPause() {
froogaloop.addEvent('pause',
function(data) {
console.log('pause event');
});
}
function onFinish() {
froogaloop.addEvent('finish',
function(data) {
console.log('finish');
});
}
onPlay();
onPause();
onFinish();
}
setupEventListeners();
}
})
我的 HTML:
<iframe src="http://player.vimeo.com/video/3718294?api=1" width="623" height="350" frameborder="0" id="iframe-video"></iframe>
I'm trying to recognize the onPlay, onPause, and onFinish event for vimeo using the froogaloop API. I've tried everything I could imagine with this thing, and no luck.
I get this error on Firefox:
And in Chrome:
Importing froogaloop from the CDN:
<script src="http://a.vimeocdn.com/js/froogaloop2.min.js"></script>
My JS:
$(function(){
var vimeoPlayer = document.querySelector('iframe');
$f(vimeoPlayer).addEvent('ready', ready);
function ready(player_id) {
froogaloop = $f(player_id);
function setupEventListeners() {
function onPlay() {
froogaloop.addEvent('play',
function(data) {
console.log('play event');
});
}
function onPause() {
froogaloop.addEvent('pause',
function(data) {
console.log('pause event');
});
}
function onFinish() {
froogaloop.addEvent('finish',
function(data) {
console.log('finish');
});
}
onPlay();
onPause();
onFinish();
}
setupEventListeners();
}
})
My HTML:
<iframe src="http://player.vimeo.com/video/3718294?api=1" width="623" height="350" frameborder="0" id="iframe-video"></iframe>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
经过几个小时的挫折......我找到了解决方案。
由于我在 iframe 上使用了 ID...显然 vimeo API 强制您将参数添加到您正在获取的 URL (player_id=iframe-id)。
所以 iFrame 应该是这样的:
特别感谢 Drew Baker 指出了这一点: http://vimeo .com/forums/topic:38114#comment_5043696
After hours and hours of frustration... I have found the solution.
Since I was using an ID on the iframe... apparently the vimeo API forces you to add the parameter to the URL you are fetching (player_id=iframe-id).
So the iFrame should look like this:
Special thanks to Drew Baker for pointing this out: http://vimeo.com/forums/topic:38114#comment_5043696
使用 jQuery 选择 iframe 时创建播放器元素时出错。
对我来说,解决方案的结果
是选择 jQuery ID 选择器中的第一个元素
Got an error creating the player element when selecting the iframe with jQuery.
Results in
Solution for me was to select the first element in the jQuery ID selector
我认为您违反了同源政策。您会注意到此处您正在做的事情很多事件处理,他们使用特殊的 froogaloop API 调用。
我从未使用过 froogaloop 所以我可能是错的。但这是我的猜测。这些错误似乎表明 iframe 正在尝试修改浏览器中的 URL,而同源现在允许这样做。这就是 API 为您包装 window.postMessage 的原因。
I think you're violating the Same Origin Policy. You'll notice here that where you're doing a lot of event handling, they are using special froogaloop API calls.
I've never used froogaloop so I'm probably wrong. But that's my guess. The errors seem to suggest that the iframe is attempting to modify the URL in your browser, and that's now allowed by Same Origin. That's why the API wraps up window.postMessage for you.
我遇到了类似的问题,但在这种情况下,用 Vimeo.Player 替换 Froggaloop 后,它仍然是 chrome 中的新限制。我收到错误“play() 失败,因为用户没有先与文档交互...”。经过进一步研究,Chrome 似乎添加了一些限制请参阅此处。我的解决方案是将
allow="autoplay"
添加到 iframe。I had a similar issue, but in this case after replacing Froggaloop with the Vimeo.Player, it still it was a new restriction in chrome. I was getting the error "play() failed because the user didn't interact with the document first...". After further research it looks like Chrome added some restrictions see here. The solution in my case was to add
allow="autoplay"
to the iframe.Froggaloop2 也遇到了类似的问题 - 看起来如果视频被缓存,则就绪事件只会触发一次(在初始加载时)。解决方案是通过更改 src 来检索 iframe,如下所示:
Having had a similar issue, with Froggaloop2 - it appears that if the video is cached, the ready event will fire only once (on the initial load). The solution is to retrieve the iframe with changing src, as: