最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught (in promise) DOMException: The element has no supported sources in audio play() - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 3

I 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!

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论