javascriptjqueryvimeovimeo-apifroogaloop

Simple pause with vimeo api Froogaloop


Trying to call the vimeo api to pause video on a click event to hide it. And, on clicking to reveal the video again, play the video from its paused position.

There are various related questions on here, I can't find an answer to the simple "how to pause". I'm a jquery novice and can't make heads or tails of the froogaloop documentation.

Here's a FIDDLE, and my current jquery script to hide the video

$(document).click(function (event) {
    if (!$(event.target).hasClass('click')) {
        $('#video').hide();
    }      
});

which hides it when an element without the "click" class is clicked. But the video plays on in the background. Froogaloop is loaded in the fiddle. Thanks everyone


Solution

  • Here's an updated FIDDLE that makes pause/play work as I'd imagined. Click the image to play the video; click outside or on empty space (you control this with classes) to pause it; click image again to play from paused position. Simple, no buttons, no excess jquery or froogaloop code.

    Putting this here for those who might benefit from it. And a +1 to mbrrw for getting me started.

    var iframe = $('#video iframe')[0];
    var player = $f(iframe);
    
    $('.showvideo').on('click', function(){
        $('#video').show();
        $('.image').hide();
        player.api('play');
    });
    
    $(document).click(function (event) {
              if (!$(event.target).hasClass('click')) { //if what was clicked does not have the class 'click' (ie. any empty space)
        $('#video').hide();
        $('.image').show();
        player.api('pause');
              }
    });
    

    Remember to append api=1 to the vimeo link. And the url must be https, not http.