HTML DOM Video buffered 屬性


HTML DOM Video buffered 屬性返回一個 TimeRanges 物件,其中包含影片緩衝區長度及其開始、結束位置的資訊。

語法

以下是語法 −

返回 TimeRanges 物件

mediaObject.buffered

讓我們來看一個 Video buffered 屬性的示例 −

示例

 即時演示

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video buffered</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-buffered</legend>
         <video id="demo" width="320" controls><source    src="https://tutorialspoint.tw/html5/foo.mp4" type="video/mp4"></video><br>
         <input type="button" onclick="getTrackDetails()" value="Get Buffered Seconds">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var demo = document.getElementById("demo");
   demo.buffered = true;
   function getTrackDetails() {
      divDisplay.textContent = 'Buffered: '+demo.buffered.end(0)+' seconds';
   }
</script>
</body>
</html>

輸出

在不播放影片的情況下單擊 ‘獲取緩衝秒數’ 按鈕 −

播放影片後單擊 ‘獲取緩衝秒數’ 按鈕 −

更新於: 2020-07-08

167 次瀏覽

開啟你的 職業生涯

完成課程以獲得認證

開始學習
廣告
© . All rights reserved.