문제

According to the vimeo js-api doc, the event finish - Fires when the video playback reaches the end.

For some reason, I can't get this to work, the finish event always calls immediately, am I doing something wrong?

I am trying to make an embedded video disappear when it is finished playing. I have followed this example by Drew Baker but simply cannot get the finish event to call properly.

I have made a very straightforward jsbin here to demonstrate the issue.

This behaviour seems to be occurring on Safari, Chrome and Firefox (on mac).

--

JS Code from JSBIN:

$(document).ready(function() {
  $('iframe.vimeo').each(function(){
    Froogaloop(this).addEvent('ready', ready);
  });

  function ready(playerID){
    Froogaloop(playerID).addEvent('play', play(playerID));
    Froogaloop(playerID).addEvent('seek', seek);
    Froogaloop(playerID).addEvent('finish', onFinish(playerID));

    Froogaloop(playerID).api('play');
  }

  function play(playerID){
    alert(playerID + " is playing!!!");
  }

  function seek() {
    alert('Seeking');
  }

  function onFinish(playerID) {
    alert(playerID + " finished!!!");
    $('#'+playerID).remove();
  }
});
도움이 되었습니까?

해결책

You are executing functions instead of passing the function reference to the addEvent method.

Froogaloop(playerID).addEvent('play', play);
Froogaloop(playerID).addEvent('seek', seek);
Froogaloop(playerID).addEvent('finish', onFinish);

Note that Froogaloop passes the playerID as an argument to the play callback function, I'm not certain that it passes the playerID as an argument to the finish callback function (although I'm guessing it probably does).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top