Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to add a short audio track to a game of concentration I'm coding. I want the sound to occur when the user has won the game. How do I go about doing this? I would really appreciate the help, thank you.

share|improve this question
This might help:… – bummzack Oct 25 '11 at 7:30
In my game, I play music with an embedded Youtube player. – jcora Dec 28 '11 at 13:55
What browsers and versions do You want to support? – Michas Dec 28 '11 at 14:36

If you're using something like canvas and you're already depending on the browser supporting HTML5, you can use the audio element.

var win = new Audio('srcfile.wav');
if(playerWon === true){;
share|improve this answer

Audio in HTML5 is a minefield at the moment, with patchy format support.

We wrote a few blog posts about audio support in HTML5. This chart shows browser support:

Surprisingly, IE doesn't support playback of WAVs. You should pick audio 2 formats to get coverage on all the platforms.

Beware using MP3's in games

It will cost you $2,500 per title in licensing fees if it has more than 5,000 distributions.

We think the best combination to use is AAC/Ogg to cover all browsers.

share|improve this answer

I found an article describing this library which should fit your needs.

If you don't have sound files yet and want to create them with some fx library then you might want to look at jsfx which I used in my last game typdown (specially these two files are interesting (don't mind the coffeescript, it all compiles to javascript): sounds and game controller

share|improve this answer

The Web Audio API is perfect for playing audio in javascript, but currently only Chrome supports it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.