Sound has allways been a hot topic regarding gameQuery. The whole idea behind gameQuery was to get rid of flash, however there isn’t really a good way to implement sound support across the range of existing browser without it. So there is a trade-of between having a pure standard javascript implementation and a mature and good supported implementation. To solve this problem gameQuery use swappable sound plugins called Sound Wrapper. To allows you to code you games without thinking about the sound backend and later choose the prefered implementation. You can even switch the implementation later, for example you can start wiht a flash based implementation (like the SoundManager wrapper) and switch to the HTML5 base implementation when more browser supports it.
Three implementation are provided: a HTML 5 one, a SoundManager one and an empty one. The most stable is obviously the SoundManager wrapper. The HTML 5 is still in developement and since HML5 specification are not finished it still evolving. The empty one (“bogus”) is there as a starting point for the developement of your own wrapper. If you’ve developped your own wrapper don’t hesitate to share it, I’ll gladly put it on this site.
A sound wrapper is in fact a sound object with a series of conventional functions. Any object that corespond to this convention can be used as sound wrapper, you can find the description of those function in the The $.gameQuery.Sound Object section bellow.
To use this wrapper you will have to add to you page SoundManager 2, that is the javascript library as well as the swf file. You also have to include the javascript files in the correct order:
To use the HTML5 sound wrapper you just need to add the script to you page. It has to be addded after the gameQuery script. There is no other requierment but keep in mind that this will be compatible only with the browser supporting the HTML5 audio object.
Except for the constructor, the methods of this object are of interest only to people developing their own wrapper.
The constructor, it take the url of the sound and a boolean to indicate if the sound should be looped or not.
This function should start the playing of the sound.
This function should pause the sound. After a call to this function a sucessive call to play()
should play the sound from the position it where paused.
This function should stop the sound. After a call to this function a sucessive call to play()
should play the sound from the start.
If true
is passed, this function should mute the sound without pausing or stoping it. If false
is passed it should unmute the sound.
This function returns true
if the sound is ready to be played, false
otherwise.