Categories
JavaScript Answers

How to check if audio is playing with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *