HTML DOM Video readyState Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Video readyState property returns a number corresponding to the current ready state of the video.

Syntax

Following is the syntax −

Returning number value

mediaObject.readyState

Here, the return value can be the following −

  • 0 (HAVE_NOTHING) depicts no information available
  • 1 (HAVE_METADATA) depicts metadata for the media is ready and video is seekable
  • 2 (HAVE_CURRENT_DATA) depicts data for the current playback position is available, but not enough data to play next frame
  • 3 (HAVE_FUTURE_DATA) depicts data for the current position and also for at least more than two frames of video
  • 4 (HAVE_ENOUGH_DATA) depicts enough data available to start playing

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

Example

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video readyState</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-readyState</legend>
         <video id="demo" width="320" controls><source src="" type="video/mp4"></video><br>
         <input type="button" onclick="setTrackDetails()" value="Set Source">
         <input type="button" onclick="getTrackDetails()" value="Get ready State">
         <div id="divDisplay">
         </div>
      </fieldset>
   </form>
   <script>
      var divDisplay = document.getElementById("divDisplay");
      var demo = document.getElementById("demo");
      var srcOfMedia = 'http://www.tutorialspoint.com/html5/foo.mp4';
      function getTrackDetails() {
         divDisplay.textContent = 'ready State: '+demo.readyState;
      }
      function setTrackDetails() {
         demo.src = srcOfMedia;
         demo.load();
      }
   </script>
</body>
</html>

Output

Clicking ‘Get ready State’ button with no source defined −

Clicking ‘Get ready State’ button with source defined −

raja
Published on 31-Oct-2019 10:40:24
Advertisements