Skip to content

Instantly share code, notes, and snippets.

@seunggabi
Last active June 28, 2019 06:00
Show Gist options
  • Select an option

  • Save seunggabi/d939d8b659acc6cc68849857856bd772 to your computer and use it in GitHub Desktop.

Select an option

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

seunggabi commented Jun 28, 2019

Copy link
Copy Markdown
Author

additional... clearInterval in play after callback

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