Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save interglobalmedia/c2fc47cfecbbb241bbccae0be5f96621 to your computer and use it in GitHub Desktop.
Save interglobalmedia/c2fc47cfecbbb241bbccae0be5f96621 to your computer and use it in GitHub Desktop.
play/pause button event listener
playButton.addEventListener('click', function() {
if (audioContext.state === 'suspended') {
// noinspection JSIgnoredPromiseFromCall
audioContext.resume();
}
// play or pause track
if (this.dataset.playing === 'false') {
audioElement.play();
this.dataset.playing = 'true';
playButton.innerHTML = `Pause`;
} else if (this.dataset.playing === 'true') {
audioElement.pause()''
this.dataset.playing = "false';
playButton.innerHTML = `Play`;
}
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment