0

Is there anyway or javascript class or function that I can used to get the duration on the embed file?

I know we can do it like this

<!DOCTYPE html> 
<html> 
<body> 

<button onclick="myFunction()" type="button">Get video length</button><br>

<video id="myVideo" width="320" height="176" controls>
  <source src="mov_bbb.mp4" type="video/mp4">
  <source src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>

<script>
var vid = document.getElementById("myVideo");

function myFunction() { 
    alert(vid.duration);
} 
</script> 

<p>Video courtesy of <a href="http://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>

</body> 
</html>

it only works on some supported browsers but not in ie8 below. Can anyone guide me how can I get the duration of the embed files? that can work on any crossbrowsers? or do I need to make a parser? please help thank you.

Lutianna
  • 543
  • 1
  • 5
  • 15
  • I originally posted the following as an answer, but strictly speaking it isn't, so deleted it; more of a comment: It looks like you should be waiting for the "loadedmetadata" event in order to access properties such as duration. See here: http://stackoverflow.com/a/19592137/792406 – hillmark May 16 '15 at 09:04
  • Although, that doesn't address the IE8 issue. – hillmark May 16 '15 at 09:06
  • still using html5 how about using it on ie7 below. is there any function that can get the duration? – Lutianna May 16 '15 at 09:08
  • also it just same they using the duration function. – Lutianna May 16 '15 at 09:09

0 Answers0