【问题标题】:Why isn't html audio autoplay working为什么html音频自动播放不起作用
【发布时间】:2018-06-26 10:49:59
【问题描述】:

这是窃听还是什么?请帮我。我正在编写一个网站,但它不起作用。我使用谷歌浏览器。是否存在兼容性问题?

<audio autoplay id="myaudio" allow="autoplay">
<source src="http://soundbible.com/mp3/Fuse Burning-SoundBible.com-1372982430.mp3.mp3" type="audio/mpeg">
</audio>
<script> document.getElementById('myaudio').play(); </script>

【问题讨论】:

  • http://soundbible.com/mp3/Fuse Burning-SoundBible.com-1372982430.mp3.mp3 不存在。删除.mp3 之一,然后它会工作。

标签: javascript html


【解决方案1】:

您的网址似乎无法正常工作。删除一个 .mp3,它应该适合你。

<audio autoplay id="myaudio" allow="autoplay">
<source src="http://soundbible.com/mp3/Fuse Burning-SoundBible.com-1372982430.mp3" type="audio/mpeg">
</audio>
<script> document.getElementById('myaudio').play(); </script>

【讨论】:

  • 您想在您的答案中添加 OP 的 sn-p 的更正版本吗?由于之前/之后的效果,可能很有用。
【解决方案2】:

如果您在运行 sn-p 的浏览器上查看控制台,您将能够看到以下错误:

Failed to load resource: the server responded with a status of 404 (Not Found)

404 错误表明客户端能够与给定的服务器通信,但服务器找不到请求的内容。

在您的情况下,服务器找不到指定的 mp3 文件。查看您的 url 中的代码和额外的 .mp3,删除它们将解决您的问题。

<audio autoplay id="myaudio" allow="autoplay">
<source src="http://soundbible.com/mp3/Fuse Burning-SoundBible.com-1372982430.mp3" type="audio/mpeg">
</audio>
<script> document.getElementById('myaudio').play(); </script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多