使用 Jquery 停止 Vimeo 视频

发布于 2024-09-19 02:02:47 字数 372 浏览 6 评论 0原文

我需要停止嵌入了新的 oembed api (通用播放器)的 Vimeo 视频,但是当我尝试添加事件时,我收到此错误:

Uncaught TypeError: Object #<an HTMLIFrameElement> has no method 'addEvent'

但我不知道为什么收到此错误,我添加了 jquery 和 frogaloop api,我也添加了添加了 id 到 iframe,但它仍然不起作用::(

完整代码在这里:

http://tv. bisaccia.info

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:

http://tv.bisaccia.info

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

羁绊已千年 2024-09-26 02:02:47

Eli,请编辑您的帖子。正如乔所说,你部分被误导了。虽然跨域通信需要 postMessage,但它是通过调用“Froogaloop.init();”添加的 DOM 方法来实现的。

is_embed_iframe = _this.iframe_pattern.test(cur_frame.getAttribute('src')); 

if (is_embed_iframe) {
        cur_frame.api = _that.api;
        cur_frame.get = _that.get;
        cur_frame.addEvent = _that.addEvent;
    }

注意:您需要从 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();"

is_embed_iframe = _this.iframe_pattern.test(cur_frame.getAttribute('src')); 

if (is_embed_iframe) {
        cur_frame.api = _that.api;
        cur_frame.get = _that.get;
        cur_frame.addEvent = _that.addEvent;
    }

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.

却一份温柔 2024-09-26 02:02:47

根据 Mike 的建议,调用:

Froogaloop.init();

确实使控制 API 工作。就我而言:

<iframe id="player_1" src="http://player.vimeo.com/video/26859570?js_api=1&js_swf_id=player_1&title=0&byline=0&portrait=0" width="620" height="354" frameborder="0"></iframe>
<script>
    $(document).ready(function() {
        Froogaloop.init();
        $("#player_1").moogaloop({
            load: function(element) {
                $("#segment1").click(function() { element.moogaloop('seekTo', "7"); });
            }
        });
    });
</script>

奇怪...Moogaloop 的作者演示页面确实在没有 init() 调用的情况下工作。无论如何,为我工作。

感谢您抽出时间!

As per Mike's suggestion, invoking:

Froogaloop.init();

Does make the control API work. In my case:

<iframe id="player_1" src="http://player.vimeo.com/video/26859570?js_api=1&js_swf_id=player_1&title=0&byline=0&portrait=0" width="620" height="354" frameborder="0"></iframe>
<script>
    $(document).ready(function() {
        Froogaloop.init();
        $("#player_1").moogaloop({
            load: function(element) {
                $("#segment1").click(function() { element.moogaloop('seekTo', "7"); });
            }
        });
    });
</script>

Weird... Moogaloop's author demo page does work without the init() call. Anyway, worked for me.

Thanks for your time!

帅的被狗咬 2024-09-26 02:02:47

这不是正确的答案,但可能适合您的情况,就像我的情况一样。我只是想在关闭包含 DOM 元素的 Vimeo 时停止播放。我正在折叠它的容器,这在视觉上隐藏了它,但音频继续播放并不必要地使用浏览器资源。

我现在所做的只是将 iframe 存储在一个变量中,将其从 DOM 中删除,然后立即替换它。我没有跨浏览器进行测试,仅测试了最新版本的 Chrome 和 Safari Mobile。

var container = $("#VimeoContainer");
var iframe = container.find("iframe");
iframe.remove();
container.append(iframe);

再说一遍,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.

var container = $("#VimeoContainer");
var iframe = container.find("iframe");
iframe.remove();
container.append(iframe);

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.

未央 2024-09-26 02:02:47

你不能。

  • 没有 DOM addEvent 方法。
  • 您没有对 Vimeo 的跨域访问权限,因此不允许您使用 JavaScript 接口与 iframe 的文档或抽象视图。

如果您想通过 JavaScript 与 Vimeo 交互,则必须让他们实现也接受您的域的 postMessage API。

You can't.

  • There's no DOM addEvent method.
  • You don't have cross-domain access to Vimeo, so you are not permitted to have JavaScript interface with the iframe's document or abstract view.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文