简体   繁体   English

Vimeo Froogaloop API无法识别事件

[英]Vimeo Froogaloop API not recognizing an event

I'm trying to recognize the onPlay, onPause, and onFinish event for vimeo using the froogaloop API. 我正在尝试使用froogaloop API识别vimeo的onPlay,onPause和onFinish事件。 I've tried everything I could imagine with this thing, and no luck. 我尝试过用这个东西想象的一切,没有运气。

I get this error on Firefox: 我在Firefox上遇到此错误:

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

And in Chrome: 在Chrome中:

不安全的javascript尝试使用URL访问框架...来自URL为http://player.vimeo.com/video/3718294?api=1的框架。域,协议和端口必须匹配。

Importing froogaloop from the CDN: 从CDN导入froogaloop:

<script src="http://a.vimeocdn.com/js/froogaloop2.min.js"></script>

My JS: 我的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: 我的HTML:

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

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). 由于我在iframe上使用了ID ...显然vimeo API会强制您将参数添加到您要获取的URL(player_id = iframe-id)。

So the iFrame should look like this: 所以iFrame看起来应该是这样的:

<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 特别感谢Drew Baker指出这一点: http//vimeo.com/forums/topic38114 #comment_5043696

Got an error creating the player element when selecting the iframe with jQuery . 使用jQuery选择iframe时创建播放器元素时出错。

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 我的解决方案是选择jQuery ID选择器中的第一个元素

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

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. 你会发现这里是哪里你做了很多的事件处理,他们使用的是特殊的froogaloop API调用。

I've never used froogaloop so I'm probably wrong. 我从来没有使用过froogaloop所以我可能错了。 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. 这些错误似乎表明iframe正在尝试修改浏览器中的URL,现在Same Source允许这样做。 That's why the API wraps up window.postMessage for you. 这就是为什么API为你包装window.postMessage的原因。

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). 有一个类似的问题,使用Froggaloop2 - 似乎如果视频被缓存,就绪事件将仅触发一次(在初始加载时)。 The solution is to retrieve the iframe with changing src, as: 解决方案是通过更改src来检索iframe,如下所示:

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

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. 我有一个类似的问题,但在这种情况下,用Vimeo.Player替换Froggaloop后,它仍然是一个新的限制铬。 I was getting the error "play() failed because the user didn't interact with the document first...". 我收到错误“play()失败,因为用户没有先与文档交互......”。 After further research it looks like Chrome added some restrictions see here . 经过进一步的研究,看起来Chrome增加了一些限制, 请看这里 The solution in my case was to add allow="autoplay" to the iframe. 我的解决方案是将allow="autoplay"添加到iframe。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM