Sometimes, we want to check if audio is playing with JavaScript.
In this article, we’ll look at how to check if audio is playing with JavaScript.
How to check if audio is playing with JavaScript?
To check if audio is playing with JavaScript, we can use the paused property of the audio element.
For instance, we write
const isPlaying = (audElem) => {
return !audElem.paused;
};
to define the isPlaying function that returns !audElem.paused.
If audElem.paused is false, then the audio is playing.
audElem is the audio element.
Conclusion
To check if audio is playing with JavaScript, we can use the paused property of the audio element.