WAI
Status Update
Comments
gr...@google.com <gr...@google.com>
gr...@google.com <gr...@google.com> #2
Thanks for reaching out! Could you provide the complete minimal repro that I can run locally to reproduce the issue?
br...@gmail.com <br...@gmail.com> #3
Attached
gr...@google.com <gr...@google.com> #4
This is not a bug, the code executes faster, that it gets the old current time. If you will wait a second, after calling seekto(), you'll for sure get the latest value. You can observe this by adding the code below.
setInterval(function(){
console.log(ytplayer.getCurrentTime());
},1000);
br...@gmail.com <br...@gmail.com> #5
OK, that's understandable. I'd only like to add that it would be helpful if this were documented. The API reference for IFrame embeds doesn't show either getCurrentTime or seekTo as being async calls. That's understandable, too, as they're probably not async calls themselves; however, there's something going on internally that must be, and I don't see that specified in the docs. Thanks for your help.
Description
- Description
seekTo(secs, true) followed by getCurrentTime() returns the wrong value for current time
For instance, suppose:
1. we have some HTML that calls the Youttube Embed API for a random video, and also has some span or div with an ID or 'currentTime', along with the following js that uses the var 'ytplayer' for it's YT.Player instance (playerVars: controls set to '1'):
function renderVideoTime() {
var ytTime = ytplayer.getCurrentTime()
$('#currentTime')[0].innerHTML = ytTime
return ytTime
}
function adjust_ytplayer_time(change) {
var ct = ytplayer.getCurrentTime()
ytplayer.seekTo( ct + change, true)
renderVideoTime()
}
2: We start the video in the player, then pause the video shortly thereafter, then use the player scroll bar to seek the video back to 0.
3. calling adjust_ytplayer_time(5) causes the video to seek to 5 seconds in with the in-video time showing correctly, but the currentTime span will show 0.
4. call adjust_ytplayer_time(5) again and the youtube video will show the right stuff for '10', but the span will show '5'.
5. call adjust_ytplayer_time(-10), and the player will be back at the start of the video, but the currentTime will show '10'
6. wait a second or two and then call renderVideoTime(), and the time in the currentTime span will be correct.
- API request with parameters used (DO NOT include your credential)
ytplayer.getCurrentTime()
ytplayer.seekTo( ct + change, true)
- Result (copy and paste a JSON response you received)
getCurrentTime returns the wrong value
- Expected result
getCurrentTime be accurate
- Is it 100% reproducible?
yup
- Reproducible API explorer link
none