Javascript DOM HTML Video readyState Property get

Introduction

Get the current ready state of the video:

Click the button to get the current ready state of the video.

View in separate window

<!DOCTYPE html>
<html>
<body>
<video id="myVideo" width="100" height="100" controls>
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>// ww w. jav a  2 s  .  com
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myVideo").readyState;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The readyState property returns the current ready state of the video.

The ready state indicates if the video is ready to play or not.

This property is read-only.

Type
Description
Number





Represents the ready state of the video element:
0 = HAVE_NOTHING - no information whether or not the video is ready
1 = HAVE_METADATA - metadata for the video is ready
2 = HAVE_CURRENT_DATA - data for the current playback position is available, but not enough data to play next frame
3 = HAVE_FUTURE_DATA - data for the current and at least the next frame is available
4 = HAVE_ENOUGH_DATA - enough data available to start playing



PreviousNext

Related