my code stopped working today (it worked before).
Here is my code:
playMe = new Audio(link);
playMe.play();
Here is the error I get in the console:
Uncaught (in promise) DOMException: Failed to load because no supported source was found.
It is really the audio.play(); that doesn't work because if I only keep the first line I don't get an error (but obviously is dos't play).
I'm using chrome 52.0.2743.82 m (64-bit)
Thanks.
Before you play audio, window must be focused. For this case you can use:
playMe = new Audio(link);
window.focus();
playMe.play();
The below answer is for video. The same you can use for audio as well.
var playPromise = document.querySelector('video').play();
// In browsers that don’t yet support this functionality,
// playPromise won’t be defined.
if (playPromise !== undefined) {
playPromise.then(function() {
// Automatic playback started!
}).catch(function(error) {
// Automatic playback failed.
// Show a UI element to let the user manually start playback.
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With