Facing Problem in retrieving HTML5 video duration


To get the video duration, query the readyState attribute. It has a series from 0 to 4. When the metadata has loaded, the value you will get is 1.

Therefore, you need to do something like −

window.setInterval(function(tm) {
   // Using readyState attriute
   if (video.readyState > 0) {
      var duration = $('#duration').get(0);
      // for video duration
      var video_duration = Math.round(video.duration);
      duration.firstChild.nodeValue = video_duration;
      clearInterval(tm);
   }
},1000);

Updated on: 24-Jun-2020

310 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements