views:

163

answers:

2

I am looking into writing web based games using just Javascript, HTML, and CSS. It seems like there are large classes of games could be done using these technologies, except for one thing. I can't really find a good way of controlling sound, the only thing I see that it works is to embedding a control of some sort into the page. Is their a way to do fine grained sound effects in DHTML?

Lets say I had a pool game and wanted to have the sounds of the balls hitting each other, is there a way to do this without using some sort of plugin?

+1  A: 

You could write a flash application without interface which you'd only have to write once and then you can communicate to it with javascript to make it play songs. It'd basically be your "sound player controlled by DHTML".

See this link: Javascript<>Flash communication explained

Tom
Essentially that's how the http://www.schillmania.com/projects/soundmanager2/ library works -- it wraps a pure JavaScript api around Flash to use Flash's sound capabilities.
artlung
Alright, didn't know about it. I guess it's a better approach for the OP as it has probably already been tested and documented well.
Tom
+3  A: 

You can use SoundManager 2 for this; SoundManager 2 is a JavaScript library for controlling sound on webpages with a nice API. Have a look at this demo page, some nice examples there, particularly A Noisy Page and Smashable Christmas Lights. Google around for other examples of SoundManager 2 usages.

Some interesting answers here: Cross-platform, cross-browser way to play sound from Javascript?. Notable links from that thread:

artlung