【问题标题】:Vimeo player api - play video with javascriptVimeo player api - 使用 javascript 播放视频
【发布时间】:2013-11-17 16:34:32
【问题描述】:

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

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

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

在 safari 按钮上不起作用。

如何让它发挥作用?

【问题讨论】:

标签: javascript vimeo


【解决方案1】:

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

&lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt;

这是它的工作原理http://jsfiddle.net/nkfH4/

【讨论】:

    猜你喜欢
    • 2016-12-28
    • 2018-12-09
    • 1970-01-01
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    相关资源
    最近更新 更多