Issue
It's a relatively simple problem that I'm not able to get:
I'm using Fancybox with a Vimeo embed and trying to auto close the fancybox once the video has ended, but I'm not able to get it to close.
Attempted Solutions
I've attempted to implement the code from this example: (Fire event when vimeo video stops playing?) and by looking at the Vimeos repository on Github: (https://github.com/vimeo/player.js)
Code
(Note: I'm attaching this to the 'afterload' event in Fancybox)
afterLoad: function (current, previous) {
// Attempted Solution 1
var iframe = $('.fancybox-iframe')[0],
player = $(iframe);
console.log(player);
$(player).ready(function() {
console.log('ready!!');
});
$(player).on('ended', function(data) {
console.log('finished!!');
$.fancybox.close();
});
// Attempted Solution 2
var iframe = $('iframe .fancybox-iframe');
var player = new Vimeo.Player(iframe);
player.on('ended', function() {
console.log('Finished.');
});
// Experiment 3
vimeo : {
color : 'red'
}
}
Results
Attempted Solution 1 works when I call (player).ready
but nothing happens when I call $(player).on('ended', function(data)
.
Attempted Solution 2 throws the error: "You must pass either a valid element or a valid id"
Attempted Solution 3 was just an attempt to see if I could control the Vimeo parameters by jQuery, but didn't get a result.
Any thoughts on what I'm missing in either of these approaches?