我打算在我的js代码中播放来自外部url的音频文件,但我在google chrome和firefox中不断收到这个错误:Uncaught (in promise) DOMException: The element has no supported sources.
和Uncaught (in promise) DOMException: The media resource indicated by the src attribute or assigned media provider object was not suitable.
。
下面是我的代码:
const sound = new Audio("https://soundcloud.com/saba-a-744718954/tick-1");
button.addEventListener("click", soundHandler);
function soundHandler() {
sound.play()
}
我很感谢你的帮助。谢谢。
发布于 2021-09-08 18:40:52
我用这个音频(audio.bfmtv.com)测试了你的代码,它工作得很好:
所以你的音频链接有问题!
const appDiv = document.getElementById('app');
appDiv.innerHTML = `<h1>Click here to start audio</h1>`;
const sound = new Audio("https://audio.bfmtv.com/bfmbusiness_128.mp3?aw_0_1st.playerId=AudioPlayer_Web_Next");
appDiv.addEventListener("click", soundHandler);
function soundHandler() {
sound.play()
}
你可以在这里尝试一下:https://stackblitz.com/edit/js-wlfkh2?file=index.html
https://stackoverflow.com/questions/69108068
复制相似问题