I have a problem with triggering the Vimeo "Finish" event in my Angular directive. The Vimeo video is loading and the play and pause functions are working correctly.
My HTML code
<vimeo control-boolean="isPlaying" vid="{{videoslist[id].code}}" pid="1"></vimeo>
<button ng-click="prevVid()">Prev</button>
<button ng-if="isPlaying" ng-click="status()">Pause</button>
<button ng-if="!isPlaying" ng-click="status()">Play</button>
<button ng-click="nextVid()">Next</button>
<div class="videoInfo">
<h2>{{videoslist[id].title}}</h2>
<p>{{videoslist[id].discription}}</p>
</div>
My AngularJS Directive
directive('vimeo', function($sce) {
return {
restrict: 'EA',
replace: true,
scope: {
//Assumes that true means the video is playing
controlBoolean: '='
},
template: '<iframe id="video"></iframe>',
link: function postLink(scope, element, attrs) {
attrs.$observe('vid', function(value) {
var url = "http://player.vimeo.com/video/" + attrs.vid + "?title=0&byline=0&portrait=0&api=1&autoplay=true";
element.attr('src', url);
var iframe = element[0],
player = $f(iframe);
player.addEvent("ready", function() {
player.addEvent('finish', onFinish);
});
function onFinish() {
console.log("vimeo finish")
}
scope.$watch('controlBoolean', function(){
if(scope.controlBoolean){
player.api('play');
}
else{
player.api('pause');
}
});
});
}
};
});
In the directive above this line should trigger the event, but it isn't:
player.addEvent("ready", function() {
player.addEvent('finish', onFinish);
});
function onFinish(id) {
console.log("vimeo finish")
}
I used this to help me with the directive: http://embed.plnkr.co/GKWNk3LhX0MR3lhpfqyA/preview
And the website of Vimeo, to read about 'How to trigger the events': http://developer.vimeo.com/player/js-api
Does someone see what I do wrong?