PDA

View Full Version : Question about the Preload Image (with progress bar) Script



Mark_D
03-31-2009, 08:23 PM
1) Script Title: Preload Image (with progress bar) Script

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex4/preloadimage.htm

3) Describe problem:
I've been working on a new web site for a friend, and I needed a "page loading" script. I found yours on Dynamicdrive.com, and it works great, thanks! It's almost exactly what I needed. One question, it works great on the graphics, but can I also use it to preload the sound (.wav file)? Is there a way to edit the script and add this option so that it will work for both, sound & graphics?

Thanks again,
Mark
Mark@durhambos.com

jscheuer1
04-01-2009, 05:04 AM
There is no actual preloading of sound files in javascript or HTML. There may be a way with Flash, Java (not javascript), or a server side language, I don't know. You can place an embed on a page with the sound file as its src attribute and set it hidden and not to play, that will preload it - sort of. But there is no way to monitor its progress as there is with images. And, if you are preloading images, they will be taking up the bandwidth anyway, so the sound file may not load until after.

However, if the embed 'runs' before the preload script, the script may wait for the sound file to load before starting on the images. At least a few images will probably load concurrently, so it is a bit of a crap shoot, but you might luck out.

Example hidden non-starting embedded wav tag:


<embed src="mysound.wav" loop="false" autostart="false" hidden="true">


If that happens, it may take some time (depending upon connection speed and the size of the sound file), but at least then the progress bar will not start moving until the browser starts in on the images.

The best chance of that happening is to put the embed tag in the body of the page and to change this in the second part of the preload script:


loadImages()

to:


window.onload = loadImages;

Mark_D
04-01-2009, 04:21 PM
Thanks for the help John,

Is there any script, and/or HTML that would allow me to mute the sound, or turn the volume all the way down while the file is loading to the "preload" page I was making? Because I'm thinking the autostart="true or false" has to be set to "true" before the file would start to load right? I'd like to run the "embed src" as "hidden", and hear no sound until the file loads and the page links over to the next page where I want the sound to play. (the old "bait and switch" tactic.) lol

Thanks again,
Mark

jscheuer1
04-01-2009, 04:30 PM
I used that exact tag to preload wav files before. It was some time ago, it worked then, perhaps still will. I think if you give no mime type or player info, the browser will cache the file, or at least start to. Therein lies the real issue, if somehow the images start and then finish preloading before the sound is completely cached, it won't help at all, in fact it will just add time to the preload page as the browser tries to deal with the sound file and the images.

Some experimentation will be necessary.

Mark_D
04-01-2009, 05:01 PM
Thanks,

I'll keep playing with it.