I have the following function as an interval to check a vimeo video’s progress every 3 seconds. The function is suppose to stop the interval when I hit the pause button…
but clearInterval does not work.
player.getPaused().then(function (paused) {
if (paused) {
clearInterval(int1)
}
})
However, this way the interval will get cleared right away as the player is initially in a paused state; what you have to do instead to make it work is listening to start / pause events:
var handle
var startPolling = function () {
handle = window.setInterval(function () {
player.getCurrentTime().then(console.log)
}, 3000)
}
var stopPolling = function () {
window.clearInterval(handle)
}
player.on('play', startPolling)
player.on('pause', stopPolling)
Or actually listen to the timeupdate event directly rather then manually polling the player state:
player.on('timeupdate', function (event) {
console.log(event.seconds)
})