End of Video Events with Vimeo
December 12, 2017
End of Video Events with Vimeo
December 12, 2017
Newbie 18 posts
Followers: 44 people

A few people asked how to create trigger an end video event with Vimeo, so here goes.

1. Create an html file (paste it into a notepad, and change the extension to .html)  with the following:

<!doctype html>

<html>

<head>

<meta charset=”utf-8″>

<title>Untitled Document</title>

</head>

<body>

//ENTER VIMEO EMBED HERE

<iframe src=”https://player.vimeo.com/video/XXXXXXXXXXX” width=”640″ height=”360″ frameborder=”0″ webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

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

<script>

    var iframe = document.querySelector(‘iframe’);

    var player = new Vimeo.Player(iframe);

    player.on(‘ended’, function() {

//ENTER END TRIGGER FUNCTION HERE

        alert(“Your Vimeo video has now ended”);

    });

</script>

</body>

</html>

2. Go to your Vimeo account, copy and paste the embed code into the html.  Also modify your ‘player.on ended’ function.  I just put in an alert to test it, but you can trigger virtually anything. I typically modify a captivate user variable so that the LMS will ‘remember’ if the video has finished or not each time a learner logs on.

3.  Zip your HTML file (use any compression program like WinRar)

4. In captivate, create a new HTML5 animation and select your newly created zip folder

5.  Test your Vimeo movie to make sure the end event is triggering.

Additional Notes

1. I typically turn off the playbar as an option from the vimeo website so that the user cannot fast forward the movie to trigger an end movie event. No cheating on my watch 🙂  To get the Vimeo movie to play from a captivate button, create a button and add the following javascript –

window.frames[0].frameElement.contentWindow.player.play();

2. The Vimeo Developer API has lots of very cool features (load movies, adding cue points, etc.) all of which can be accessed through their javascript API.  Check out

https://player.vimeo.com/api/demo

and

https://github.com/vimeo/player.js

if you need more features.

3. Another one I typically use is the player.loadVideo if I need to show another Vimeo video.  Just create a captivate button with the following JS

window.frames[0].frameElement.contentWindow.player.loadVideo(THE ID NUMBER OF YOUR VIDEO HERE);

You can find the video ID number will be somewhere on the Vimeo website or in the embed code.  This makes it really easy to switch videos.

 

I hope this helps.

 

 

 


Addition.

Here is the .cptx file already with the imported HTML5 animation .zip.   When the video ends (you can fast forward) it:

end of Video Triggers vimeo

Sends an alert, changes a cp variable, and shows a button.  The code in the zip file is:

player.on(‘ended’, function() {
alert(“The video has ended.”);
parent.triggerMe = “Played”;
parent.cp.show(‘nextBtn’)
});

Hope this helps.

 

All Comments
Sort by:  Most Recent
Apr 7, 2022
Apr 7, 2022

Can a similar script be used for Wistia’s API?

Like
()
Dec 11, 2018
Dec 11, 2018

Thank you for this code. I had some problems with it so I posted what you had into Dreamweaver and it showed mixing ‘ ” and the angled one. I changed them so they were all the same and it works like your sample. Thanks again!

Like
(2)
Feb 14, 2018
Feb 14, 2018

That’s the js for the rewind button and it looks ok. Is there any script that’s running on frame enter? When does your unexpected token error fire?

Like
(2)
(3)
Feb 14, 2018
Feb 14, 2018
>
Jeremy Shimmerman
's comment

No other script is running on frame entry. I’m not sure what an unexpected token error is? I’m new to JS. The syntax error pops up on click of the button.

Like
(2)
Feb 14, 2018
Feb 14, 2018
>
marissat22566383
's comment

Unexpected token just means there’s a typo somewhere. There’s an extra bracket or comma somewhere. Maybe try this, delete and replace the commas around ‘RangeError’. Sometimes Captivate changes the font when copying and pasting script into its js editor.

They should be single commas and look like a straight line – not curled.

Like
(2)
Feb 14, 2018
Feb 14, 2018
>
Jeremy Shimmerman
's comment

That fixed it!! Wonderful! This is great. Thank you!

Like
(2)