How does html5 get the length of the current video?
This article will explain in detail how html5 obtains the length of the current video. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Example
Get the length of the current video:
MyVid=document.getElementById ("video1"); alert (myVid.duration)
Definition and usage
The duration property returns the length of the current audio / video in seconds.
If audio / video is not set, NaN (Not-a-Number) is returned.
Browser support
All major browsers support the duration attribute.
Note: this property is not supported by Internet Explorer 8 or earlier browsers.
Grammar
Audio | video.duration
Technical details
Returns a numeric value that represents the length of audio / video in seconds.
According to the program on page P489 in JavaScript advanced programming, I wrote the following program
Video player is not available.
0/0
_ window.onload=function () {var oPlayer=document.getElementById ('player'); var oBtn=document.getElementById ("video-btn"); var oCurtime=document.getElementById (' curtime'); var oDuration=document.getElementById ('duration'); oDuration[ XSS _ clean] = oPlayer.duration;oBtn.onclick=function () {if (oPlayer.paused) {oPlayer.play (); oBtn.value= "Pause";} else {oPlayer.pause (); oBtn.value= "Play";}}; setInterval () {oCurtimexss _ clean] = oPlayer.currentTime;};}
Because the video tag is not supported in IE8 and previous versions, it is not displayed.
But when IE9,10,11 supports it, why does it show
Also, use alert (oPlayer.duration); the page can pop up the time of the video.
But why does the sentence oDuration [XSS _ clean] = oPlayer.duration; show NaN?
In response, I tried the code again.
Var duration1=oPlayer.duration;alert (duration1); / / NaNalert (oPlayer.duration); / / 3625.982
From the above results, you can see that after assigning the value of oPlayer.duration to a variable, the value of that variable is NaN. But why? By definition, the oPlayer.duration property returns a numeric value, so why does a numeric value become NaN to a variable? I don't understand yet.
This is the end of the article on "how to get the length of the current video by html5". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.