admin管理员组

文章数量:1429098

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.

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.

Share Improve this question edited May 13, 2013 at 2:07 Lachlan McDonald asked May 13, 2013 at 1:51 Lachlan McDonaldLachlan McDonald 2,4342 gold badges24 silver badges26 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

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.

本文标签: javascriptvideojs currentTime() incorrect until timeupdate event firesStack Overflow