0

I'm just created html program to play an Mp3 file using javascript. Its working fine if the program runs from a google chrome, but it wont works with firefox(version24, OS:ubuntu). And it outputs some error in console like "HTTP "Content-Type" of "audio/mpeg" is not supported. Load of media resource http://localhost/phpsound/sound_file.mp3 failed". Do I need to install any plugin for firefox to solve this issue. Please help me to solve this issue.

Html code:

<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>
Arjun Pokkattu
  • 129
  • 2
  • 17

2 Answers2

2

Firefox can't play mp3, but can play files in ogg format.

So you just need to provide an additional ogg file and it should work.


If you are wondering why, see this question: Why doesn't Firefox support the MP3 file format in <audio>

Community
  • 1
  • 1
Simone
  • 20,302
  • 14
  • 79
  • 103
  • From the MDN documentation: "The MP3 audio format (.mp3, audio/mpeg; distinct from the above MP3 audio in an MP4 container case) is supported in – sica07 Nov 12 '13 at 10:02
  • 1
    This information is outdated, see this post and references: http://stackoverflow.com/questions/4923136/why-doesnt-firefox-support-mp3-file-format-in-audio/12203792#12203792 – dan-lee Nov 12 '13 at 10:04
  • I just changed the file format .mp3 to .ogg, but it output another error in console like HTTP "Content-Type" of "text/plain" is not supported. Load of media resource http://localhost/phpsound/sound_file.ogg failed. – Arjun Pokkattu Nov 12 '13 at 10:11
0

Audio element() does not support .mp3 file format in Firefox, It only supports .WAV and .ogg file formats.

Vishwas
  • 6,967
  • 5
  • 42
  • 69