Skip to content

Instantly share code, notes, and snippets.

@BroFox86
Last active December 16, 2020 20:25
Show Gist options
  • Save BroFox86/ffc36d5e8649dee3f37468a624ce0804 to your computer and use it in GitHub Desktop.
Save BroFox86/ffc36d5e8649dee3f37468a624ce0804 to your computer and use it in GitHub Desktop.
[Pause audio] Pause previous track when the next track starts playing #media
// Pause current track when another track starts playing.
document.addEventListener("play", ({ target }) => {
const audios = document.querySelectorAll("audio");
for ( const audio of audios ) {
if ( audio !== target ) {
audio.pause();
}
}
}, true
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment