I have a vanilla JS web app that plays a sound in reaction to a certain event, and the press of a button stops the sound. That all works fine.
However, I recently started using a dedicated media play/pause button on my mouse and I notice that this button resumes playback of the last sound in that tab, even after it has already been cancelled.
Can I prevent this somehow? For stopping, I'm currently using the standard solution mentioned in this answer:
sound.pause();
sound.currentTime = 0;
This is in Firefox on Windows 10.
I thought of doing preventDefault on the key event since there is no reason to play/pause these (alarm) sounds as though they were media tracks. But basic research suggests that this event is handled by the browser and is not available to JS.