previousnext

Our ball can bounce ... but it is so quiet in here. Real balls make a sound when they bounce; so should ours!

I have embedded some <audio> tags in the html source code, and made the sound files available as indicated. They look something like the following:

<audio id="wall_sound" preload>
  <source src="../sounds/tock.wav" type="audio/x-wav">
  <source src="../sounds/tock.ogg" type="application/ogg">
  <source src="../sounds/tock.mp3" type="audio/mpeg">
</audio>

The reason for including three copies, in different formats, of the same sound file, is that various browsers (with the exception of Chrome) only support one or two of the above formats without additional plugins, and no format is supported by all the browsers. By including all three formats, individual browsers can find one they support.

I should add that I used Audacity to convert the original file into the other two formats.

Although I have not tried it, according to html5media, it is possible to avoid having to do this by linking to their library; you may want to have a look.

Note

I used this sound file from Freesound to create the bouncing sound. I had to edit it and make it shorter as it sometimes would not be heard if two collisions occurred within a short time frame.

Experiment!

Try it! You may notice that the speaker button seems to do nothing... We'll do something about that soon.

previousnext