Created
May 10, 2020 21:06
-
-
Save interglobalmedia/c2fc47cfecbbb241bbccae0be5f96621 to your computer and use it in GitHub Desktop.
play/pause button event listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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