Sometimes, we want to get the current YouTube video time with JavaScript.
In this article, we’ll look at how to get the current YouTube video time with JavaScript.
How to get the current YouTube video time with JavaScript?
To get the current YouTube video time with JavaScript, we use the getCurrentTime
method.
For instance, we write
const ytPlayer = document.getElementById("movie_player");
const time = ytplayer.getCurrentTime();
to select the YouTube player element with getElementById
.
Then we call getCurrentTime
to get the current time of the video.
Conclusion
To get the current YouTube video time with JavaScript, we use the getCurrentTime
method.