HTML DOM Video duration 属性
htmlweb developmentfront end technology更新于 2024/5/26 5:00:17
HTML DOM Video duration 属性返回一个与视频长度(以秒为单位)对应的数字。
注意 − 对于直播流,它返回 ‘Inf’,这是无限的,因为直播流没有预定义的时长。
语法
以下是语法 −
返回字符串值
mediaObject.duration
让我们看一个 HTML DOM Video duration 属性的示例 −
示例
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video duration</title>
<style>
* {
padding: 2px;
margin:5px;
}
form {
width:70%;
margin: 0 auto;
text-align: center;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>HTML-DOM-Video-duration</legend>
<video id="demo" width="320" controls><source src="http://www.tutorialspoint.com/html5/foo.mp4" type="video/mp4"></video><br>
<input type="button" onclick="getTrackDetails()" value="How many seconds of content is this video?">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var demo = document.getElementById("demo");
function getTrackDetails() {
divDisplay.textContent = 'Duration: '+demo.duration+' seconds';
}
</script>
</body>
</html>
输出
点击"这个视频有多少秒?"按钮之前 −

点击这个视频有多少秒?"按钮之后 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

