Javascript 无法加载,因为找不到支持的来源。播放 HTML5 音频元素时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37217606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 20:03:00  来源:igfitidea点击:

Failed to load because no supported source was found. when playing HTML5 audio element

javascripthtmlgoogle-chromeaudiochromium

提问by Sergii Bishyr

I have HTML5 audio element

我有 HTML5 音频元素

<audio src="/sounds/call.wav" id="audio1" repeated="0" repetitions="1" class="audio_sound"></audio>

If I try to call element.play()strange error appears in Chrome web console.

如果我尝试调用element.play()Chrome 网络控制台中出现的奇怪错误。

Uncaught (in promise) DOMException: Failed to load because no supported source was found.

未捕获(承诺)DOMException:无法加载,因为找不到支持的源。

I haven't found any clues why this error appears and how to fix it.

我还没有找到任何线索,为什么会出现这个错误以及如何解决它。

回答by Andrew Serong

This may or may not help, but I ran into the same error message on an .mp3 source file. I'd been updating the content and refining the mp3, not realising that the browser had cached the original version of the mp3 file (or part of it, at least). I can't find any info to back this up, but anecdotally it seems that part of the audio file might be cached and when the browser attempts to retrieve the rest of the file, it can't (or doesn't) retrieve a full working version.

这可能有帮助,也可能没有帮助,但我在 .mp3 源文件上遇到了相同的错误消息。我一直在更新内容并优化 mp3,没有意识到浏览器已经缓存了 mp3 文件的原始版本(或至少其中的一部分)。我找不到任何信息来支持这一点,但有趣的是,音频文件的一部分似乎可能被缓存,当浏览器尝试检索文件的其余部分时,它无法(或不)检索完整的工作版本。

I'd try renaming your .wav file to something you haven't used before and see if it starts working.

我会尝试将您的 .wav 文件重命名为您以前从未使用过的文件,看看它是否开始工作。