Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

video.js currentTime() incorrect until timeupdate event fires

I've noticed a small inconsistency that I'm hoping to verify as either a quirk of HTML5, or something specific to Video.js.

It seems that if you call Video.js' currentTime() function whilst providing a new time, any further calls to currentTime() (to get the current time) will not return the correct time (it will return the previous time), until the timeupdate event fires. After the timeupdate event, currentTime() will return the correct time.

For example, assuming the video hasn't started playing yet, but Video.js has loaded, along with all the video meta etc:

videoPlayer.addEvent('timeupdate', function() {
    console.log('Event callback: ' + player.currentTime); 
});
console.log('Original time: ' + player.currentTime);  
player.currentTime(100);          
console.log('New time: ' + player.currentTime);  

The output I was expecting would look like:

Original time: 0
New time: 100
Event callback: 100

However what I've receiving is:

Original time: 0
New time: 0
Event callback: 100

Any insight would be fantastic!

Edit: I can reproduce this in Chrome and Safari on OSX, but not Firefox on OSX (all using HTML5). I can also reproduce this on IE8 using the Flash player and IE9 using the HTML5 player.

like image 897
Lachlan McDonald Avatar asked May 13 '13 01:05

Lachlan McDonald


1 Answers

I've seen similar behaviour on several other html5/flash players.

I've always been under the assumption that even after seeking via currentTime(100);, the playhead will not be updated until the next timeupdate event.

like image 98
Broonix Avatar answered Oct 21 '22 06:10

Broonix