Reputation: 143
I'm trying to get my Vimeo Embedded player to call a function when a video is done. I can't get the callback function to call....
$.getJSON('http://www.vimeo.com/api/oembed.json?url=' + encodeURIComponent('http://vimeo.com/7100569') + '&width=513&height=287&callback=?', function(data) {
$('#mediaplayerHolder').html(data.html);
$('iframe').each(function() {
$f(this).addEvent('ready', function(player_id) {
$f(player_id).addEvent('finish', function() {
alert("finish");
});
});
});
});
Upvotes: 1
Views: 1518
Reputation: 143
I figured it out... for anyone else with the same problem it was because of a couple things.
1) I didn't have
api=1
in the JSON string.
2) I needed an ID in the JSON string and the iframe.
I put it all in a function to call the videos:
function playVideo(ID,autoPlay,playNext) {
$('#mediaplayerHolder').find("iframe").remove();
$.getJSON('http://www.vimeo.com/api/oembed.json?url=' + encodeURIComponent('http://vimeo.com/' + ID) + '&title=0&byline=0&portrait=0&autoplay=' + autoPlay + '&width=513&height=287&api=1&player_id=mediaplayer&callback=?', function(data) {
$(data.html).attr("ID","mediaplayer").appendTo('#mediaplayerHolder');
var iframe = $("iframe")[0],
player = $f(iframe);
player.addEvent("ready", function() {
player.addEvent("finish",function() {
if (playNext) {
$(".occupied:not(#" + ID + "):first").find(".playBtn").click();
$("#" + ID).find(".removeBtn").click();
}
});
});
});
}
Upvotes: 2