簡體   English   中英

無法在Firefox中播放Mp3文件

[英]Cant play an Mp3 file in firefox

我剛剛創建了html程序,使用javascript播放Mp3文件。 如果程序從谷歌瀏覽器運行,它的工作正常,但它不適用於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文件,它應該工作。


如果您想知道原因,請看這個問題: 為什么Firefox不支持<audio>中的MP3文件格式

Audio element()在Firefox中不支持.mp3文件格式,它只支持.WAV和.ogg文件格式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM