D
D
doktorpull2014-01-17 13:28:27
JavaScript
doktorpull, 2014-01-17 13:28:27

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>

It is necessary that the time of the file is displayed here
<span class="time">3:15</span>
Tell me, I will be very grateful.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
itspers, 2014-01-17
@itspers

document.getElementById("myvideo").addEventListener('loadedmetadata', function() {
    console.log(document.getElementById("myvideo").duration);
});

N
Nikolai Vasilchuk, 2014-01-17
@Anonym

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

D
doktorpull, 2014-01-17
@doktorpull

<video  width="480" height="270">
       <source src="http://doktorpull.myjino.ru/uploads/files/1388073459_pixel-news-v1.mp4">
    </video>

No, can this be addressed?

D
doktorpull, 2014-01-22
@doktorpull

@Anonym it doesn't output anything? =(
1390393389_34535.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question