S
S
Sergey Burduzha2019-11-07 14:03:45
JavaScript
Sergey Burduzha, 2019-11-07 14:03:45

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();

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Bogachev, 2019-11-07
@serii81

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 question

Ask a Question

731 491 924 answers to any question