Search code examples
javascriptfirefoxaudiofirefox-oshowler.js

Play mp3 using howler.js in Firefox


I'm trying to develop a simple application that play .mp3 files. For that I'm using Howler.js. I used bellow code to play an mp3 but I'm not sure why I'm not able to hear the sound.

<!DOCTYPE html>
<html">
<head>
    <title>Play Sound</title>
    <script src="howler.min.js"></script>
</head>
<body>
  <button id="btn">Play</button>

  <script>
      var pong = new Howl({urls: ['pong.wav']});
      document.getElementById('btn').onclick=function(){pong.play();}
  </script>
</body>
</html>

Well, I have a small .wav file pong.wav (7.08kb) which I'm able to play using the application. But if I try to play other file like .mp3, I don't get any sound. This problem is only with Firefox browser (as Firefox does not have codec for mp3) but work fine with Chrome. So, what to do to play .mp3 in Firefox browser (more interested to implement in Firefox OS simulator/device).


Solution

  • urls: ['pong.ogg', 'pong.mp3']
    

    place the url to the .ogg file first