vimeo / player.js

Interact with and control an embedded Vimeo Player.

Home Page:https://player.vimeo.com/api/demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Changing quality setting causes setInterval to accelerate

peejallegiance opened this issue · comments

Expected Behavior

Count the seconds the player has been playing

Actual Behavior

Changing quality setting on the Vimeo player causes setInterval to accelerate

Steps to Reproduce

Consider the following code. This will count the seconds as the player plays. However, changing the quality setting in the embedded player will make this count faster each time a new quality setting is selected.

//calculate watchtime
players[i].on('playing', function(data) {
    paused = false;
    timer = setInterval(totalWatchTime, 1000);

});

function totalWatchTime(){
    if(!paused){
        console.log("watchTime" + watchTime);
        watchTime += 1;
        localStorage.setItem("watchTime", watchTime);
    }
}

This code does not account for any of the cases where playback is paused, including when the quality is switched.

The easiest thing would be to use getPlayed() instead, but that only counts the sections of the video played, not the total time. If you need the total time, you will have to account for pauses, so you want to look at computing the difference with the currentTime on timeupdate and excluding cases where it changes from seeking or buffering.

If you need more assistance with it, the discussions here would be more appropriate, or contact Vimeo support.