Computer >> Computer tutorials >  >> Programming >> HTML

HTML5 check if audio is playing


Use the following to check if audio is playing −

functionisPlaying(audelem) {
   return!audelem.paused;
}

The above code can be used to check ifaudio is playing or not. The audio tag has a paused property.The paused property returns whether the audio/video is paused.

You can also toggle −

functiontogglePause() {
   if(newAudio.paused && newAudio.currentTime > 0 && !newAudio.ended) {
      newAudio.play();
   } else {
      newAudio.pause();
   }
}