Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery how to stop Vimeo video when click

here is the simple code: http://jsfiddle.net/YAFuW/1/

basicly i tried to use like this:

<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');
});
like image 480
test Avatar asked May 01 '12 17:05

test


2 Answers

The best way is to work with Vimeo API:

Example:

<script>
    var iframe = $('.vimeo-iframe').get(0);
    var player = new Vimeo.Player(iframe);
    player.pause();
    //player.play();
</script>
like image 139
Roy Shoa Avatar answered Oct 15 '22 06:10

Roy Shoa


You missed get the id of the vimeo video:

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

Example: 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>
like image 32
JoanR Avatar answered Oct 15 '22 04:10

JoanR