Reputation: 862
I know how to get the current elapsed time of a youtube video using...
player.getCurrentTime()
But I need a way to show this as updating text inside an element so I can display the current time of the youtube video counting while the video is playing. What's the correct way to do this preferably using jquery?
Upvotes: 1
Views: 5842
Reputation: 17
Here's a working code playground example that should help:
https://code.google.com/apis/ajax/playground/#polling_the_player
Upvotes: 0
Reputation: 27317
If the player doesn't offer a callback when the seconds roll over, you could still poll the current time. Choosing the correct polling frequency is a performance trade-off, but you don't really need to crank it up:
setInterval(function(){
display.innerText = player.getCurrentTime();
},100); //polling frequency in miliseconds
jQuery does not really simplify the waiting but you can use it for DOM manipulation:
setInterval(function(){
$display.text(player.getCurrentTime());
},100); //polling frequency in miliseconds
Upvotes: 4