HTML5 Game Programming: Making Noise with the Sound Object

By Andy Harris

Part of HTML5 Game Development For Dummies Cheat Sheet

You use the Sound object to create two sounds per object — an MP3 and an OGG — to ensure the sound effects in your game will work on most HTML5-compliant browsers.

sndElement = new Sound(src) Creates a new Sound object called
sndElement based on the src
file. This file should be in MP3, OGG, or WAV format.
play() Plays the current sound.
showControls() Displays the HTML5 sound control panel with a volume control
and scrubber. Can be useful for iOS devices that require manual
sound playback before code-based playback.