Javascript DOM HTML Audio readyState Property

Introduction

Get the current ready state of the audio:

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio" controls>
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>/*from  ww w .j a  v a 2  s  . c  o m*/
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>

The readyState property returns the ready state of the audio.

This property is read-only.

The readyState property returns a number which represents the ready state of the audio element:

Value Meaning
0 = HAVE_NOTHING no information whether or not the audio is ready
1 = HAVE_METADATA metadata for the audio 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