Vimeo Froogaloop API 无法识别事件

发布于 2024-11-18 04:36:35 字数 1831 浏览 7 评论 0原文

我正在尝试使用 froogaloop API 识别 vimeo 的 onPlay、onPause 和 onFinish 事件。我已经尝试了所有我能想象到的东西,但没有运气。

我在 Firefox 上收到此错误:

<code><http://player.vimeo.com></code> 获取宠物属性 Location.toString 的权限被拒绝

在 Chrome 中:

不安全的 JavaScript 尝试访问具有 URL 的框架 ... 来自具有 URL `http://player.vimeo.com/video/3718294?api=1 的框架 域、协议和端口必须匹配。

从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:

Permission denied for <code><http://player.vimeo.com></code> to get pet property Location.toString

And in Chrome:

Unsafe javascript attempt to access frame with URL ... from frame with URL `http://player.vimeo.com/video/3718294?api=1. Domains, protocols and ports must match.

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 技术交流群。

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

发布评论

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

评论(5

‖放下 2024-11-25 04:36:35

经过几个小时的挫折......我找到了解决方案。

由于我在 iframe 上使用了 ID...显然 vimeo API 强制您将参数添加到您正在获取的 URL (player_id=iframe-id)。

所以 iFrame 应该是这样的:

<iframe src="//player.vimeo.com/video/3718294?api=1&player_id=promo-vid" 
        width="623" height="350" frameborder="0"
        id="promo-vid">
</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:

<iframe src="//player.vimeo.com/video/3718294?api=1&player_id=promo-vid" 
        width="623" height="350" frameborder="0"
        id="promo-vid">
</iframe>

Special thanks to Drew Baker for pointing this out: http://vimeo.com/forums/topic:38114#comment_5043696

蔚蓝源自深海 2024-11-25 04:36:35

使用 jQuery 选择 iframe 时创建播放器元素时出错。

var iframe = $('#player1');
var player = $f(iframe);

对我来说,解决方案的结果

TypeError: d[f] is undefined

是选择 jQuery ID 选择器中的第一个元素

var iframe = $('#player1')[0];
var player = $f(iframe);

Got an error creating the player element when selecting the iframe with jQuery.

var iframe = $('#player1');
var player = $f(iframe);

Results in

TypeError: d[f] is undefined

Solution for me was to select the first element in the jQuery ID selector

var iframe = $('#player1')[0];
var player = $f(iframe);
や三分注定 2024-11-25 04:36:35

我认为您违反了同源政策。您会注意到此处您正在做的事情很多事件处理,他们使用特殊的 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.

回梦 2024-11-25 04:36:35

我遇到了类似的问题,但在这种情况下,用 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.

还不是爱你 2024-11-25 04:36:35

Froggaloop2 也遇到了类似的问题 - 看起来如果视频被缓存,则就绪事件只会触发一次(在初始加载时)。解决方案是通过更改 src 来检索 iframe,如下所示:

$(iframe).attr('src', $(iframe).attr('src') + '#timestamp='+(new Date()).getTime());

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:

$(iframe).attr('src', $(iframe).attr('src') + '#timestamp='+(new Date()).getTime());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文