10

这是简单的代码:http: //jsfiddle.net/YAFuW/1/

基本上我试着像这样使用:

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

<a href="#">STOP</a>

$('a').click(function() {
   alert('stoped');
   froogaloop.api('unload');
});
4

5 回答 5

15

我不知道完成这个跨浏览器的“好”或“正确”方式。
Youtube 的 JavaScript API 也失败了。

但是这种方法是可靠的并且确实有效。
基本上,它会杀死<iframe>并重建它。

$('a').click(function() {
  alert('stoped');
  vimeoWrap = $('#vimeoWrap');
  vimeoWrap.html(vimeoWrap.html());
});

在 JSFiddle 查看

于 2012-05-01T18:27:47.863 回答
14

如果您只需要播放或暂停视频,请像这样使用:

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

$('#stop').click(function() {
    alert('stoped');
    player.api('pause');
});


$('#play').click(function(){
    alert('play');
    player.api('play');
})

和标记:

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

<iframe id="vimeo-player" src="http://player.vimeo.com/video/40977539?api=1" width="400" height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<a id="stop" href="#">STOP</a>
<a id="play" href="#">PLAY</a>

http://jsfiddle.net/zimm/8CV2S/14/

于 2012-10-17T10:52:44.030 回答
4

最好的方法是使用Vimeo API

例子:

<script>
    var iframe = $('.vimeo-iframe').get(0);
    var player = new Vimeo.Player(iframe);
    player.pause();
    //player.play();
</script>
于 2017-10-22T08:59:32.580 回答
3

您错过了获取 vimeo 视频的 id:

var iframe = $('#vimeo-player')[0];
var player = $f(iframe);
player.api('unload');

示例:http: //jsfiddle.net/joan_r/dutzh512/

<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://a.vimeocdn.com/js/froogaloop2.min.js"></script>
<style>
#play,#pause,#stop{
    width:60px;
    margin:5px;
    text-align: center;
    border: solid;
    cursor:pointer;
}
</style>
</head>
<body>
<iframe id="vimeo-player" src="//player.vimeo.com/video/76979871" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<div id="play">[PLAY]</div>
<div id="pause">[PAUSE]</div>
<div id="stop">[STOP]</div>
<script>
    $('#play').click(function() {
        var iframe = $('#vimeo-player')[0];
        var player = $f(iframe);
        player.api('play');
    });
    $('#pause').click(function() {
        var iframe = $('#vimeo-player')[0];
        var player = $f(iframe);
        player.api('pause');
    });
    $('#stop').click(function() {
        var iframe = $('#vimeo-player')[0];
        var player = $f(iframe);
        player.api('unload');
    });
</script>
</body>
</html>
于 2015-03-05T10:59:40.610 回答
0

如果您使用 Vimeo 更新的 API 代码,那么您可以这样做:http: //jsfiddle.net/deshg/8CV2S/。您可以看到停止按钮现在向您发出警报,然后视频被卸载。

干杯!

于 2012-07-11T11:35:03.770 回答