HTML5 check if audio is playing

HTMLWeb DevelopmentFront End Technology

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();
   }
}
raja
Published on 20-Mar-2018 15:36:26
Advertisements