Vimeo player api - play video with javascript

烂漫一生 提交于 2019-12-20 02:23:05

问题


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

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

On safari buttons just do not work.

How to make it work?


回答1:


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

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



来源:https://stackoverflow.com/questions/19812091/vimeo-player-api-play-video-with-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!