HTML DOM Video preload Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Video preload property returns a string corresponding to when the creator thinks the video data should load. Though sometimes this may be ignored.Default value is ‘metadata’.

Syntax

Following is the syntax −

Returning string value

mediaObject.preload

Setting preload to a string

mediaObject.preload = “auto|metadata|none”

Let us see an example of HTML DOM Video preload property −

Example

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video preload</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-preload</legend>
         <video id="demo" width="320" preload=”none” controls><source
         src="http://www.tutorialspoint.com/html5/foo.mp4" type="video/mp4"></video><br>
         <input type="button" onclick="getTrackDetails()" value="Preload Video">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
   <script>
      var divDisplay = document.getElementById("divDisplay");
      var demo = document.getElementById("demo");
      divDisplay.textContent = 'Data Savings mode on. Play video to load it';
      function getTrackDetails() {
         demo.preload = 'metadata'
         divDisplay.textContent = 'Data Savings mode off. Preload enabled';
      }
   </script>
</body>
</html>

Output

Before clicking ‘Preload Video’ button −

After clicking ‘Preload Video button −

raja
Published on 31-Oct-2019 10:37:23
Advertisements