Answer the question
In order to leave comments, you need to log in
Why in chrome video.duration is equal for some NAN videos?
Good afternoon.
I brought a video gallery on the page, but without the control panel.
Also output the time for each of the videos.
In chrome, for some videos, the time is defined as NAN.
And in firefox everything is fine.
How to fix it?
Here is my code.
let showVideoTime = function () {
let videoPageGallery = document.querySelectorAll('.video-page .video-page__item video');
for (let i = 0; i < videoPageGallery.length; i++){
var mind = videoPageGallery[i].duration % (60 * 60);
var minutes = Math.floor(mind / 60);
var secd = mind % 60;
var seconds = Math.ceil(secd);
$(videoPageGallery[i]).parent().append('<span class="video-time">'+minutes+': '+seconds+'</span>');
}
};
showVideoTime();
Answer the question
In order to leave comments, you need to log in
Try to wait for the loadedmetadata event for the video, maybe they just do not have time to load by the time the script is executed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question