Nick P
Nick P

Reputation: 769

Vimeo player SDK - set video as ended

We are handling the Vimeo player.js ended event and asking a user to submit questions which is a postback.

When the page reloads, the video is at the start again - this can apparently confuse users. So I'd like to add some JS to just set the video as ended again. I tried this.

player.getDuration().then(function(duration) {
  player.setCurrentTime(duration);
});

However this does not work as it shows the last frame(s) but does not show the final slide (which is shown as a static image when the video is truly ended). This is likely because getDuration() only returns a whole number of seconds if the video is not played yet, but returns the real fractional seconds after playback starts, so we aren't quite at the end.

However, if I attempt to store and pass the real fractional seconds to setCurrentTime(), I get an error:

Seconds must be a positive number less than the duration of the video (<whole number>)

So it seems setCurrentTime() cannot be used like this, it validates against the integer value of getDuration() if the video has not started playing. Even if it has, this works but does not show the end slide.

Is there a way to fix this apart from calling player.play() to force it to advance, which might blip the sound/animation for a fraction of a second? If not, I'll need to make the postback AJAX instead. I tried a hacky workaround in hiding the video, setting volume to zero, calling play, then show it on the ended event but the flickering is jarring.

Upvotes: 0

Views: 83

Answers (0)

Related Questions