使用 Jquery 停止 Vimeo 视频
我需要停止嵌入了新的 oembed api (通用播放器)的 Vimeo 视频,但是当我尝试添加事件时,我收到此错误:
Uncaught TypeError: Object #<an HTMLIFrameElement> has no method 'addEvent'
但我不知道为什么收到此错误,我添加了 jquery 和 frogaloop api,我也添加了添加了 id 到 iframe,但它仍然不起作用::(
完整代码在这里:
I need to stop a Vimeo video embedded with new oembed api (universal player) but when I try to add an event I get this error:
Uncaught TypeError: Object #<an HTMLIFrameElement> has no method 'addEvent'
But I don't why I get this error, I added jquery and the frogaloop api, also I added ids to the iframes, but it still doesn't work: :(
The full code is here:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Eli,请编辑您的帖子。正如乔所说,你部分被误导了。虽然跨域通信需要 postMessage,但它是通过调用“Froogaloop.init();”添加的 DOM 方法来实现的。
注意:您需要从 Vimeo 站点获取 froogaloop.js(或 min 变体)。
请确保在调用 init() 之前设置 iFrame“src”,否则 froogaloop 将不执行任何操作。
Eli, please edit your post. As Joe said, you are partially misinformed. While postMessage is needed for cross-domain communication, it is implemented through a DOM method added by a call to "Froogaloop.init();"
Note: you will need to grab froogaloop.js (or the min variant) from the Vimeo site.
Be sure the iFrame "src" is set prior to calling init(), otherwise froogaloop will do nothing.
根据 Mike 的建议,调用:
确实使控制 API 工作。就我而言:
奇怪...Moogaloop 的作者演示页面确实在没有 init() 调用的情况下工作。无论如何,为我工作。
感谢您抽出时间!
As per Mike's suggestion, invoking:
Does make the control API work. In my case:
Weird... Moogaloop's author demo page does work without the init() call. Anyway, worked for me.
Thanks for your time!
这不是正确的答案,但可能适合您的情况,就像我的情况一样。我只是想在关闭包含 DOM 元素的 Vimeo 时停止播放。我正在折叠它的容器,这在视觉上隐藏了它,但音频继续播放并不必要地使用浏览器资源。
我现在所做的只是将 iframe 存储在一个变量中,将其从 DOM 中删除,然后立即替换它。我没有跨浏览器进行测试,仅测试了最新版本的 Chrome 和 Safari Mobile。
再说一遍,Froogaloop 确实是可行的方法,但是我过去在使用它时遇到过问题,因此对于这种情况,我正在寻找一些简单的东西。显然,您可以在没有 JQuery 的情况下执行此操作,并获得相同的结果。
This is not the correct answer, but may work for your situation as it did for mine. I simply wanted to stop my Vimeo from playing when I closed its containing DOM element. I was collapsing its container and that hid it visually but the audio continued to play and use browser resources unnecessarily.
What I do now is simply store the iframe in a variable, remove it from the DOM, then replace it immediately. I have NOT tested across browsers, only the latest version of Chrome and Safari Mobile.
Again, Froogaloop is really the way to go, however I've had issues with it in the past so for this situation I was looking for something simple. Obviously you could do this without JQuery with the same results.
你不能。
addEvent
方法。如果您想通过 JavaScript 与 Vimeo 交互,则必须让他们实现也接受您的域的
postMessage
API。You can't.
addEvent
method.If you wanted to interface with Vimeo via JavaScript, you would have to get them to implement a
postMessage
API that also accepts your domain.