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:
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.
Can a similar script be used for Wistia’s API?
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!
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?
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.
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.
That fixed it!! Wonderful! This is great. Thank you!
Thanks for this. I got it all working except for the play button. I created a button and added an advanced action to it using the code”window.frames[0].frameElement.contentWindow.player.play();” but nothing happens. I am having the same issue trying to do the 15 second rewind. Am I executing the action incorrectly? Am I forgetting to add something to the beginning of the code?
Hi Marissa. I’d have to take a look at it to see what’s wrong. If you press f12 in your browser you can see if any errors are being triggered. The only thing I could think of off hand is that if you have more than one iframe on the slide, you need to make sure you’re scripting to the right one.
If the end of video ‘alert’ is being triggered, you know that Vimeo’s player.js API has loaded properly. Let me know if you see any errors. Thanks
Thanks for the response. I only have 1 iframe on the page. I’m on a mac. Is Cmd+opt+I the equivalent to f12? When I go to the console it shows this:
SyntaxError: Invalid or unexpected token
at eval ()
at Function.a.runJavascript (CPM.js:1751)
at eval (eval at executeAction (CPM.js:2026), :1:4)
at cp.Movie.executeAction (CPM.js:2026)
at Function.b.clickSuccessHandler (CPM.js:1956)
at Function.b.clickHandler (CPM.js:1955)
at b.ch (CPM.js:1955)
at Function.a.handleClickExternal (CPM.js:1420)
at HTMLDivElement.a.handleClick (CPM.js:1421)
Also wanted to add that I got the play button working. It’s only the rewind which I’m now getting a error for. Thanks in advance.
You have a typo somewhere in your script. Send me your js and I’ll see if I can find it.
Here’s what I have:
window.frames[0].frameElement.contentWindow.player.getCurrentTime().then(function(sec) {
var rwd = sec -15
window.frames[0].frameElement.contentWindow.player.setCurrentTime(rwd).then(function(seconds) {
}).catch(function(error) {
switch (error.name) {
case ‘RangeError’:
break;
default:
break;
}
});
}).catch(function(error) {
});
Thanks Jeremy. I would appreciate that.
I think YouTube somehow is not the platform to use for ‘incompany’ courses (mostly because there will always be a link on the video to the YouTube website).
Since Vimeo was no option, I also tried Wistia. But I could not find a way to disable keyboard shortcuts either.
I know this functionality is not a foolproof way to make sure the users watch the video (they can start the video and walk away…) But my customer prefers it like this. So I am importing the videos in Captivate right now. It works. The videos are not that big (20-30mb). But it does not ‘feel’ as the way it should be done.
Thanks a lot. Works great.
You mention you turn off the playbar so that the user cannot fast forward the movie to trigger an end movie event. Unfortunately that does not prevent a user from using the keyboard shortcuts to fast forward the video… So I was wondering if you know of a solution to prevent fast forwarding with the keyboard shortcuts for the Vimeo player?
Yikes. Thanks for pointing this out to me. I didn’t realize the keyboard would still be enabled if you turn the playbar off. On YouTube you can simply add disablekb in the embed code. Vimeo doesn’t have that option and there doesn’t seem to be any documentation on how to disable the keyboard listeners.
I’m going to have to work on this one for a bit. Doesn’t seem to be any simple solution.
Thanks for sending that my way. I’ll see if I can come up with any workarounds that will disable key strokes and send it your way as well.
I know this is from a long time ago but I needed to re-visit Vimeo and remembered this thread.
I found a workaround to disable the keystrokes, as well as getting rid of the annoying play button in the center. It’s a bit hacky but it works.
1. Place a transparent box over the iframe. This will disallow focus on the player and will disable the keystrokes from working.
2. In the vimeo embed, put ?background=1 in the code. This will disable the buttons. You will also need to include muted=0, and autoplay = 0 (if you are controlling with another button.
Try window.parent.cp.show(‘nextBtn’)
Something seems to block it, but what?
var iframe = document.querySelector(‘iframe’);
var player = new Vimeo.Player(iframe);
player.on(‘ended’, function() {
//ENTER END TRIGGER FUNCTION HERE
window.parent.cp.show(‘nextBtn’);
console.log (‘video acabou!’);
});
The ‘ended’ trigger must be firing if your console log message is being shown. Maybe try using jQuery to show the button instead of the captivate function. Try it with and without the added ‘c’.
$(“#nextBtnc” ).show();
$(“#nextBtn” ).show();
If that doesn’t work, try all the methods with a different smartShape. Maybe there’s something unique with the button you created.
Sorry. I can’t check the link – it’s giving me a 404.
window.parent.$(‘#nextBtnc’).hide();
You would need to add the parent to the Jquery.
Sorry, try it again!
http://uniaguadoce.com.br/up_captivate/201712012024535a21ba95a174a/test-vimeo3/
It works with ‘postMessage’, but i cannot used it because my domain changes.
It seems to be working with me in the console window when I try it with the cp.show method – Both in the top and iframe level
window.parent.cp.show(‘nextBtn’)
Really? Why not for me?
Could you example the ‘player.on ended’ function triggering a next button on Captivate? Mine´s not working…
If you want to show a button you need to put ‘parent’ in front. Try this:
player.on(‘ended’, function() {
alert(“Video has ended”);
parent.cp.show(‘nextBtn’)
});
You also can troubleshoot by pressing F12 and entering your browser’s console. That will show you any errors that might be popping up.
Thanks, Jeremy Shimmerman
But it still not working… At the console, there are no error and the alert is correctly shown, but the button still hidden.
Have you named the button correctly? Under the shape title it should read nextBtn exactly. It’s case sensitive.
When you test it in your console you can also try entering in the code manually to see where the problem is. Try writing in cp.show(‘nextBtn’). That should work on the top level. Then switch to the Vimeo iFrame level and try parent.cp.show(‘nextBtn’).
Yes,Jeremy Shimmerman . Name is correct, cp.show works on top level, but not on vimeo iframe level.
In Iframe level, script stop working after parent.cpshow and nothing more is executed. But, in console, none message is displayed.