D
D
doktorpull2014-01-22 15:41:02
JavaScript
doktorpull, 2014-01-22 15:41:02

Why does determining the duration of a video file through JavaScript not work?

I asked for help in solving this problem. How to determine the duration of a JavaScript video file and display it on the site? I need to determine the duration of the video file through javaScript. They helped me. But for some reason the code doesn't work. I don't know much about code. And for this I need your help.

<h2>Видео контент номер 1</h2><span class="time">тут выводит время</span>
<video id="myvideo" width="480" height="270">
       <source src="http://doktorpull.myjino.ru/uploads/files/1388073459_pixel-news-v1.mp4">
    </video>

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

Help with a solution, thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolai Vasilchuk, 2014-01-22
@Anonym

Stop duplicating questions! You have been given a code. He works. Everything is displayed and working on JSFiddle. What else do you need?

D
doktorpull, 2014-01-22
@doktorpull

@Anonym he doesn't display the duration of the video in the span tag
<span class="time">тут выводит время</span>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question