A
A
Anatoly2018-12-12 03:19:47
YouTube
Anatoly, 2018-12-12 03:19:47

How to know the duration of a YouTube video before it starts playing?

I can't figure out why I have all the videos 1 second longer before they start playing.
Codepen.io example
Line 85: console.log(Math.floor(player.getDuration()));
By F12 we open the Console and see 17 sec, this is already rounded up from 16.7 sec.
Next, run the video, and get 16 seconds!
How so?
And this is with almost any video. 1 sec is certainly not critical, but somehow it hurts the eye.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2018-12-12
@Tolly

read about Math.floor)))
Replace withplayer.getDuration().toFixed(1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question