HTML5 Game - Audio Network State

Introduction

Network State can determine the network activity.

It returns 4 numbers, from 0 to 3, which correspond to the following states:

  • Constant Meaning
  • NETWORK_EMPTY the element has not yet been initialized.
  • NETWORK_IDLE the correct audio/video file has been chosen, but is not currently using the network.
  • NETWORK_LOADING The audio/video is being downloaded.
  • NETWORK_NO_SOURCE Either none of the given files are compatible or no file was provided.

networkState is a read-only property.

Demo

ResultView the demo in separate window

<!DOCTYPE html>
<html>
  <body>
    <audio controls>
        <source src='http://java2s.com/style/demo/your.ogg' type='audio/ogg; codecs=vorbis'>
         <source src='http://java2s.com/style/demo/your.mp3' type='audio/mpeg'>
    </audio>
    <script>
      let ele = document.querySelector('audio');

function logNetworkState()  {/*from  ww  w.  ja  v  a 2 s  .c om*/
  console.log(ele.networkState);
}
      </script>
  </body>
</html>

Related Topic