gpt4 book ai didi

javascript - 无法在 Firefox 中播放 Mp3 文件

转载 作者:行者123 更新时间:2023-12-02 18:08:11 26 4
gpt4 key购买 nike

我刚刚创建了 html 程序来使用 javascript 播放 Mp3 文件。如果程序从 google chrome 运行,它可以正常工作,但不能在 firefox(版本 24,操作系统:ubuntu)上运行。它在控制台中输出一些错误,如 "HTTP "Content-Type" of "audio/mpeg" is not supported. Load of media resource http://localhost/phpsound/sound_file.mp3 failed" 。我需要为 Firefox 安装任何插件来解决这个问题吗?请帮我解决这个问题。

HTML 代码:

<html>
<head>
<title></title>
<meta http-equiv="content-type" content="audio/mpeg">
<script language="JavaScript" type="text/javascript">
function play_sound()
{
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'sound_file.mp3');
audioElement.setAttribute('autoplay', 'autoplay');
audioElement.load();
audioElement.play();
}
</script>

<body>
<input type="button" name="btnOk" id="btnOk" value=" OK " onClick="play_sound();"/>
</body>
</html>

最佳答案

Firefox 无法播放 mp3,但可以播放 ogg 格式的文件。

所以您只需要提供一个额外的 ogg 文件就可以了。

<小时/>

如果您想知道原因,请参阅此问题:Why doesn't Firefox support the MP3 file format in <audio>

关于javascript - 无法在 Firefox 中播放 Mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19926008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com