Get the current network state of the audio:
var x = document.getElementById("myAudio").networkState;
Click the button to get the network state of the audio.
<!DOCTYPE html> <html> <body> <audio id="myAudio" controls autoplay> <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 av a 2 s . c o 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>
The networkState
property returns the current network activity of the audio.
It returns a number which represents the current network state of the audio element.
The networkState
property return values:
Type | Description |
---|---|
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 |