Computer >> Máy Tính >  >> Lập trình >> HTML

HTML DOM Thuộc tính thời lượng video


Thuộc tính thời lượng Video DOM HTML trả về một số tương ứng với thời lượng của video (tính bằng giây).

LƯU Ý - Đối với các luồng trực tiếp, nó trả về ‘Inf’ là vô hạn vì luồng trực tiếp không có thời lượng xác định trước.

Cú pháp

Sau đây là cú pháp -

Trả về giá trị chuỗi

mediaObject.duration

Hãy để chúng tôi xem ví dụ về Thời lượng video DOM HTML tài sản -

Ví dụ

<!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>

Đầu ra

Trước khi nhấp vào ‘Video này dài bao nhiêu giây nội dung?’ nút -

HTML DOM Thuộc tính thời lượng video

Sau khi nhấp vào ‘ Video này dài bao nhiêu giây nội dung?’ nút -

HTML DOM Thuộc tính thời lượng video