Answer the question
In order to leave comments, you need to log in
How to determine the duration of a JavaScript video file and display it on the site?
Tell me how to display the total time of the video file on the site
using JavaScript .
<h2>Видео контент номер 1</h2><span class="time">3:15</span>
<video id="myvideo" width="480" height="270">
<source src="http://doktorpull.myjino.ru/uploads/files/1388073459_pixel-news-v1.mp4">
</video>
<span class="time">3:15</span>
Answer the question
In order to leave comments, you need to log in
document.getElementById("myvideo").addEventListener('loadedmetadata', function() {
console.log(document.getElementById("myvideo").duration);
});
(function(window) {
var videoNode = window.document.querySelector('#myvideo');
var timeNode = window.document.querySelector('.time');
videoNode.addEventListener('loadedmetadata', function(e) {
var duration = videoNode.duration.toFixed(1);
var m = duration % 60;
timeNode.innerText = Math.floor(duration / 60) + ':' + (m < 10 ? '0' : '') + m;
});
})(window);
<video width="480" height="270">
<source src="http://doktorpull.myjino.ru/uploads/files/1388073459_pixel-news-v1.mp4">
</video>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question