Triggeer event at vimeo time point

Viewed 163

In the following JS, I have triggered a console message 'Finished' at the completion of a Vimoe video. Using the same API, is there a way to trigger it not at the end of the video but at 95% of it?


jQuery(document).ready(function() {

var iframe = jQuery('iframe#vimeo');
var player = new Vimeo.Player(iframe);

player.on('ended', function() {
    console.log('Finished.');
  });
});
1 Answers

Thanks...played around with it, working here:

<iframe src="https://player.vimeo.com/video/446508598" width="640" height="360" frameborder="0" allowfullscreen allow="autoplay; encrypted-media"></iframe>
<p>
<button style="background:red">Click</button>
</p>
<script src="https://player.vimeo.com/api/player.js"></script>
<script>
    var iframe = document.querySelector('iframe');
    var player = new Vimeo.Player(iframe);

    player.on('play', function() {
        console.log('played the video!');
    });

    player.on('ended', function() {
        console.log('ended the video!');
    });

    player.on('timeupdate', function(data) {

        /*if (data.percent > 0.01) {
            console.log('1% of video watched');
        }*/

        if (data.seconds > 10) {
            console.log('10s of video watched');
            jQuery("button").css("background", "green");
        }


    });
</script>
Related