1

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).

Rahul Chakrabarty
  • 2,149
  • 7
  • 39
  • 70
  • Mozilla say: The MP3 audio format (.mp3, audio/mpeg; [...]) is supported in – Gio May 30 '14 at 11:42
  • @Gio OS: Windows 7, Browser: Firefox 29.0.1 – Rahul Chakrabarty May 30 '14 at 11:55

2 Answers2

3

To get full browser coverage, you need to use more than one audio format, which is why howler.js asks for an array in the urls property. howler.js will then play the sound that is supported by that browser. For example:

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

You can see details about the support media formats here:

https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats

James Simpson
  • 13,488
  • 26
  • 83
  • 108
  • Thank you for making Howler plugin, Initially i used [this](http://stackoverflow.com/questions/10105063/how-to-play-a-notification-sound-on-websites) post to play a sound for push notification, when notification arrives i called a java script function to play but unfortunately chrome disables javascript execution when minimized , but when i used Howler it works great. But is there a feature to add 30 seconds silence for every loop ? – Shaiju T Jul 25 '16 at 15:03
0
urls: ['pong.ogg', 'pong.mp3']

place the url to the .ogg file first