View Full Version : poll in javascript

11-05-2012, 01:00 PM
I'm using youtube api to get to know when a video is fully buffered

when the fraction is 1, the video is fully buffered
but I have to poll this function to check whether it is 1 and then get the time
like setInterval(display_fraction,1);
since a video could be tens of minutes
will this polling creates a heavy load on the browser/client and thus affect the video streaming? are there any other better polling methods or ways to detect when youtube finishes buffering?

BTW, the link for youtube api is:

11-05-2012, 07:45 PM
Instead of testing every millisecond why not test just a few times a second - make the 1 into 250 to test four times a second or 500 to test twice a second.

11-05-2012, 09:28 PM
there is the onStateChange event listener which "fires whenever the player's state changes" - if I understand correctly I'm guessing that you would be looking for 5 (video cued), which is fired once the buffering has finished and the video is ready to play.