Problem retrieving HTML5 video duration?

The issue is in WebKit browsers; the video metadata is loaded after the video so is not available when the JS runs. You need to query the readyState attribute; this has a series of values from 0 to 4, letting you know what state the video is in; when the metadata has loaded you'll get a value of 1 So you need to do something like: window. SetInterval(function(t){ if (video.

ReadyState > 0) { var duration = $('#duration'). Get(0); var vid_duration = Math. Round(video.

Duration); duration.firstChild. NodeValue = vid_duration; clearInterval(t); } },500) I haven't tested that code, but it (or something like it) should work There's more information about media element attributes on developer.mozilla.org.

The issue is in WebKit browsers; the video metadata is loaded after the video so is not available when the JS runs. You need to query the readyState attribute; this has a series of values from 0 to 4, letting you know what state the video is in; when the metadata has loaded you'll get a value of 1. So you need to do something like: window.

SetInterval(function(t){ if (video. ReadyState > 0) { var duration = $('#duration'). Get(0); var vid_duration = Math.

Round(video. Duration); duration.firstChild. NodeValue = vid_duration; clearInterval(t); } },500); I haven't tested that code, but it (or something like it) should work.

There's more information about media element attributes on developer.mozilla.org.

Awesome... this works perfectly. Thanks for the help. – drebabels Apr 20 '10 at 13:18.

Do that: myVideoPlayer. AddEventListener('loadedmetadata', function() { console. Log(videoPlayer.

Duration); }); Gets triggered when the browser received all the meta data from the video.

1 Thanks, a much cleaner way than the accepted answer (imo). – frank hadder Sep 7 '10 at 22:08 Instead of continuously polling as in the accepted answer this one actually gets called as soon as the video knows it has its metadata available. Much cleaner indeed.

– Silvia Apr 26 at 11:12.

This is the modification to your code var duration = document. GetElementById("duration"); var vid_duration = Math. Round(document.

GetElementById("video"). Duration); //alert(vid_duration); duration. InnerHTML = vid_duration; //duration.firstChild.

NodeValue = vid_duration; Hope this helps. It looks like you're using IE, why don't you use document. GetElementById method to retrieve video object?

Thanks for the response. Unfortunately it doesn't work... I am still having the same issue where without calling the alert statement... the video duration just doesn't get pulled in (it just shows up as 0) And I don't really have a reason for not using getElementById... I just like jQuery selectors so I was using them. – drebabels Feb 9 '10 at 4:08 Well, you got 2 video sources in 1 video tag, could you put each source under 1 video tag and see if it works?

– The Elite Gentleman Feb 9 '10 at 8:57.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions