Vimeo 播放器 api - 使用 javascript 播放视频

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19812091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 16:53:51  来源:igfitidea点击:

Vimeo player api - play video with javascript

javascriptvimeo

提问by Tamara

I'm trying to start playing video with javascript/jquery function. I copy example from vimeo siteand upload it to the server, but it is not working.

我正在尝试使用 javascript/jquery 函数开始播放视频。我从vimeo 站点复制示例并将其上传到服务器,但它不起作用。

<script type="text/javascript" src="/themes/js/froogaloop.js"></script>
<script type="text/javascript">
$(function(){
    var iframe = $('#player1')[0],
        player = $f(iframe),
        status = $('.status');

// When the player is ready, add listeners for pause, finish, and playProgress
    player.addEvent('ready', function() {
        status.text('ready');

        player.addEvent('pause', onPause);
        player.addEvent('finish', onFinish);
        player.addEvent('playProgress', onPlayProgress);
    });

  // Call the API when a button is pressed
    $('button').bind('click', function() {
        player.api($(this).text().toLowerCase());
    });

    function onPause(id) {
        status.text('paused');
    }

    function onFinish(id) {
        status.text('finished');
    }

    function onPlayProgress(data, id) {
        status.text(data.seconds + 's played');
    }


});
</script>

<iframe id="player1" src="http://player.vimeo.com/video/27855315?api=1&player_id=player1"   width="400" height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

<p>Video status: <span class="status">...</span></p>
<p><button>Play</button> <button>Pause</button></p>

On firefox I got message: "Content loading is blocked"

在 Firefox 上,我收到消息:“内容加载被阻止”

On safari buttons just do not work.

在 safari 按钮上不起作用。

How to make it work?

如何使它工作?

回答by okcoker

You would need to make sure you're including the jQuery library for this code. Before the froogaloop script try adding:

您需要确保包含此代码的 jQuery 库。在 froogaloop 脚本之前尝试添加:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

Here's a fiddle of it working http://jsfiddle.net/nkfH4/

这是它工作的小提琴http://jsfiddle.net/nkfH4/