HTML DOM 동영상 재생 시간 속성은 동영상 길이(초)에 해당하는 숫자를 반환합니다.
참고 − 실시간 스트림의 경우 'Inf'를 반환합니다. 라이브 스트림에 미리 정의된 기간이 없기 때문에 무한합니다.
구문
다음은 구문입니다 -
문자열 값 반환
mediaObject.duration
HTML DOM 동영상 재생 시간의 예를 살펴보겠습니다. 속성 -
예시
<!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="https://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> 출력
'이 동영상의 콘텐츠 길이는 몇 초인가요?'를 클릭하기 전에 버튼 -

'이 동영상의 콘텐츠 길이는 몇 초입니까?'를 클릭한 후 버튼 -
