Forum Moderators: open

Message Too Old, No Replies

Can sounds be preloaded?

Avoiding delay in playing dynamic sounds

         

briansue2002

2:58 am on Nov 19, 2008 (gmt 0)

10+ Year Member



Hello,

I am creating a website where when the user performs certain actions (like clicking things), a sound plays. In IE, I am using BGSOUND. However, the only way I can get the BGSound to dynamically play is by setting the "src" attribute to the sound file (i.e. bgsound.src="http://whatever/soundfile.mp3"). When I do this, it goes back to the server to get the file each time. So, there is a delay. If my user clicks on a few objects quickly, they may miss some sounds because they click on the next object before the sound linked to the first object finishes downloading.

Is there a way to dynamically play sounds without having the browser always go back to the server to retrieve the sound files? I know with images, you can preload them, so they reside in browser cache, so you don't have to keep going back to the server to get them. Can you do that with sounds?

Thanks.

swa66

3:10 am on Nov 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For those cases when I have sound actually turned on, a website that makes noise is a sure where's the back button, can't press it fast enough. Personally I think playing music is like <blink> and lots of moving gifs: just don't even think of it unless you have a very good and compelling reason to do it.

briansue2002

3:14 am on Nov 19, 2008 (gmt 0)

10+ Year Member



my website is a game. it needs boings and bangs when players do certain things. :)

rocknbil

2:59 pm on Nov 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there a way to dynamically play sounds without having the browser always go back to the server to retrieve the sound files?

Flash is the most graceful solution here, you wait until all data's loaded and then display the interface. Embedded files won't cut it.

enigma1

3:37 pm on Nov 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try using the language of your web-server to force resource caching on the client's end. I believe sounds should be no different than any other resource like images.

You create a file that processes the mp3s to the client end and in that file you output the mp3 along with a 304 header for a predefined period of time.

You need to setup a header to specify the resource type, otherwise the client may not know what to do with the resource (as it would be something like .php).

eg:
bgsound.src="http://whatever/all_sounds.php?sound=soundfile.mp3"

then the all_sounds.php will output the headers along with the specific mp3 file that is passed as a parameter (or you could use some database and pass an index only). This should also work whether you use flash or any other type of resource.

penders

3:27 pm on Nov 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Flash is the most graceful solution here, you wait until all data's loaded and then display the interface. Embedded files won't cut it.

Yeah, from what I've heard, Flash would be the best/most reliable method. Not just from a caching point of view, but for cross-browser support and timing as well. The flash would contain just the sounds. JS would interface with your Flash object. (I think someone has made available an object which handles a lot of this for you...?)