'How to perform action at particular instant of audio

I have a certain audio and i want to perform an action at particular times, for instance at 5 sec, 10 sec and 20 sec. I also need that when the user pause the audio , the actions happen at 5, 10 sec and 20 sec from the beginning of the audio anyway. I can only use vanilla js. I tried using setTimeout but when the user pause the audio and then click play, the timeOut starts again from that specific second.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source