I intend to play an audio file from an external url in my js code, but I keep getting this error of Uncaught (in promise) DOMException: The element has no supported sources.
in google chrome and Uncaught (in promise) DOMException: The media resource indicated by the src attribute or assigned media provider object was not suitable.
in firefox.
And here is my code:
const sound = new Audio(";);
button.addEventListener("click", soundHandler);
function soundHandler() {
sound.play()
}
I appreciate any help. Thanks.
I intend to play an audio file from an external url in my js code, but I keep getting this error of Uncaught (in promise) DOMException: The element has no supported sources.
in google chrome and Uncaught (in promise) DOMException: The media resource indicated by the src attribute or assigned media provider object was not suitable.
in firefox.
And here is my code:
const sound = new Audio("https://soundcloud./saba-a-744718954/tick-1");
button.addEventListener("click", soundHandler);
function soundHandler() {
sound.play()
}
I appreciate any help. Thanks.
Share Improve this question asked Sep 8, 2021 at 18:32 SabaSaba 3735 silver badges20 bronze badges2 Answers
Reset to default 3I try your code with this audio (audio.bfmtv.), and it's work very well :
So you have problem with you audio link !
const appDiv = document.getElementById('app');
appDiv.innerHTML = `<h1>Click here to start audio</h1>`;
const sound = new Audio("https://audio.bfmtv./bfmbusiness_128.mp3?aw_0_1st.playerId=AudioPlayer_Web_Next");
appDiv.addEventListener("click", soundHandler);
function soundHandler() {
sound.play()
}
You can try it here : https://stackblitz./edit/js-wlfkh2?file=index.html
The URL passed to the Audio
element has to resolve to some audio.
You're passing it the URL to an HTML document!