joon
joon

Reputation: 864

How do I play sounds in Firefox with HTML5 Canvas? (Works in Chrome)

I have this code, in a HTML5 Canvas game:

var snd1 = new Audio("shoot.mp3"); // buffers automatically when created

and later I have:

if (data.PlaySound == "1") snd1.play();

This works in Chrome, but not at all in Firefox or Safari.

You can test the game for yourself at http://glitchnap.com/zumbie but you need a mobile device connected to generate any sounds. The whole mobile thing has no effect on the HTML5, it's just a canvas that places objects (and generates sounds) based on what the server tells it to do.

Upvotes: 0

Views: 137

Answers (1)

markE
markE

Reputation: 105015

I think as of this date Firefox and Safari do not support mp3 codec.

It's an economic thing: MP3 comes with hefty royalty payments when distributed commercially.

You'll have to supply your audio in WebM or Ogg Theora format when your user's browser is Firefox or Safari.

Upvotes: 1

Related Questions