Skip to content

Instantly share code, notes, and snippets.

@seunggabi
Last active June 28, 2019 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seunggabi/d939d8b659acc6cc68849857856bd772 to your computer and use it in GitHub Desktop.
Save seunggabi/d939d8b659acc6cc68849857856bd772 to your computer and use it in GitHub Desktop.
Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.
window.__autoPlay = setInterval(() => {
this.playTracks();
}, 500);
const promise = new Audio('/temp.mp3').play();
if (promise !== undefined) {
promise.then(() => {
window.__autoPlay && clearInterval(window.__autoPlay);
}).catch(() => {});
}
@seunggabi
Copy link
Author

seunggabi commented Jun 28, 2019

additional... clearInterval in play after callback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment