Fire event when vimeo video stops playing?

Ryano picture Ryano · Jan 31, 2013 · Viewed 21.6k times · Source

I was just wondering if it was possible to fire an event once a vimeo video has finished playing?

Currently I have a Vimeo embed in an overlay, that I want to remove once the video has stopped. Hope this makes sense!

I dont really have any code that would be of use, but would like to know if you can add event listeners to the video, fire an event once the video has finished, and how you would go about doing this?

Thanks Ryan

Answer

Concept211 picture Concept211 · Jan 8, 2017

Previous answer is now obsolete since Vimeo launching the new Video Player API.

Important: Be sure to remove the ?api=1 from the URL in your iframe. This was previously required when using the Froogaloop library and is no longer needed. If you leave it in, the 'ended', 'seeked' and other events will never fire.

Include the new script:

<script src="https://player.vimeo.com/api/player.js"></script>

And then use the following example:

$(document).ready(function(){

    var iframe = $('#container iframe');
    var player = new Vimeo.Player(iframe);

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

});