Audio networkState Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Audio

Description

The networkState property returns the current network activity of the audio.

Return Value

Type Description
Number Represents the current network state of the audio element:
  • 0 = NETWORK_EMPTY - audio has not yet been initialized
  • 1 = NETWORK_IDLE - audio is active and has selected a resource, but is not using the network
  • 2 = NETWORK_LOADING - browser is downloading data
  • 3 = NETWORK_NO_SOURCE - no audio source found

The following code shows how to get the current network state of the audio:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio" controls autoplay>
  <source src="your.ogg" type="audio/ogg">
  <source src="your.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>/*from  ww  w.  j a v  a2 s .co m*/

<button onclick="myFunction()">Test</button>

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

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

</body>
</html>

Related Tutorials