How do I preload sound on a web page with JavaScript before the page loads or as the page loads up?

Hi,

I have a web page and I want to preload some sound on the web page BEFORE the page loads up. The sound file is quite big (4mb). I want something like <body onLoad="???"> You see I have some animation on the web page and I want to sound to preload and THEN play BEFORE the animation starts. I can not use flash I have to use JavaScript. How can I do this? It needs to work for Netscape and IE. I have tried <BGSOUND id="BGSOUND_ID" LOOP=1 SRC="music.mp3">
<EMBED NAME="Bach" SRC="music.mp3" LOOP="FALSE" AUTOSTART="FALSE" HIDDEN="TRUE" MASTERSOUND> but that doesn’t preload the sound first it only loads the sound once the page has loaded and the animation has started creating a time delay difference between the animation and sound. Can some one please help me?

Thank you
LVL 2
Rawdon HumeDeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fritz_the_blankCommented:
<EMBED NAME="mySound" SRC="mySound.mid"
LOOP=FALSE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND>

FtB
0
Rawdon HumeDeveloperAuthor Commented:
hi,

that will play the sound but will it preload and play the sound before anything else? When I tried it before it played the sound when the page had loaded and once the animation had started. Some times the animation would be half way though before the sound would play as it took that long to load? Dose this code go in the body or head section of the html code?

cheers
0
Rawdon HumeDeveloperAuthor Commented:
also where in the code u give me do i put sound file name "music.mp3" ?

cheers
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

fritz_the_blankCommented:
This site here claims that it will do the preload:

http://www.javascripter.net/faq/sound/preload.htm

Now we have to figure out the proper order to call your animation...

FtB
0
fritz_the_blankCommented:
0
fritz_the_blankCommented:
<EMBED NAME="Bach" SRC="music.mp3"
LOOP=FALSE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND>
0
Rawdon HumeDeveloperAuthor Commented:
hi,

you can see my site and the animation at: http://www.geocities.com/rabidlemming8888/Untitled-4.htm

i have put the code you gave me in the head section but it dosnt seam to work?

cheers
0
Rawdon HumeDeveloperAuthor Commented:
hi,

could some one llok at my web page source code and tell me why its not working?

thank you
0
fritz_the_blankCommented:
I just tried it and it works fine for me--it takes a little time to load, however.

FtB
0
fritz_the_blankCommented:
I think that it was the amount of time it took to preload the music file, but the music started with the animation.

Fritz the Blank
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rawdon HumeDeveloperAuthor Commented:
hi,

thanks it working now, i put the code you gave me in the head and body section and it worked. thanks big time for your help

cheers
0
fritz_the_blankCommented:
I am glad to have helped.

Please consider using a lower-bitrate sound file to get the size down.

Best of luck,

Fritz the Blank
0
Rawdon HumeDeveloperAuthor Commented:
hi,

i dont know how to compress it any more as its already as an mp3 low quality sound file that inst that long, but for some reson its a large file?

the odd thing most of all is that the sound dosnt always play when you load the web page, like now it was working a moment ago and now its not working?

cheers
0
fritz_the_blankCommented:
I would consider trying to find some sort of Midi file that has the sound that you want. Midi files are really small and will work even with dial-up connections.

Fritz the Blank
0
Rawdon HumeDeveloperAuthor Commented:
hi,

thanks i will have to try that,

could you please try that link again for me as the sound isnt working now and i have not changed any thing? sorry i know im a pain and its asking alot but its stoped working now????


thank you soooooo much ur the best =0)
0
fritz_the_blankCommented:
I get the following error message:

The data that the plugin requested, did not download successfully.

I did a little poking around, and the message usually means that your server is not passing the data along.

Fritz the Blank
0
Rawdon HumeDeveloperAuthor Commented:
hi,

any idea how to fix the problem????

cheers
0
fritz_the_blankCommented:
Don't take this with the wrong tone, but get a real web host. Geocities is great in that it is free, but it is not reliable for streaming audio/video. They may even have a daily maximum of how much data you can transfer per day.

Using a smaller file will help no matter what you do.

--Fritz the Blank
0
Rawdon HumeDeveloperAuthor Commented:
hi,

so howcan i convert the mp3 file to a midi file, what sort of pogram do i need to use

also can you recomment a good web host, i do have an account with tripod with is provided by lycos is that any good?

thank you for all your help if theirs any way i can even make it back up to you feel free to ask

cheers
0
fritz_the_blankCommented:
I am happy to help--you're great to work with.

I don't think that you can convert that way. I was just thinking that if you did a google search for midi files that you might find one that you could use.

Otherwise, you will have to use an expensive program like Sonar to create your own techno tracks.

There are many good web hosting companies, but they will cost you between $10-20 /  month.

Fritz the Blank
0
Rawdon HumeDeveloperAuthor Commented:
thanks,

i already pay for the geocites and tripod ones so i will try the web page on tripods and hope that works,

http://rabidlemming8888.tripod.com/Untitled-4.htm

thanks
0
fritz_the_blankCommented:
The tripod link starts the music straight away.

FtB
0
Rawdon HumeDeveloperAuthor Commented:
hi,

is that meant to happen, i dont mind just so long as the sound plays or is their a way of fixing that?

cheers
0
fritz_the_blankCommented:
I don't understand...

FtB
0
Rawdon HumeDeveloperAuthor Commented:
hi,

sorry, i bet ur well sick and tired of me now lol

what i meant sorry was The tripod link starts the music straight away?

but its ok now as it plays the sound and sems to be working properly.

thank you sooooo much for all your help, if ever i can repay the faviour feel free to ask

cheers big time =0)
0
fritz_the_blankCommented:
Good luck with your project,

FtB
0
Rawdon HumeDeveloperAuthor Commented:
hi,

thank you again,

is their a name i can give credit to on the ankowlegemnet list for you ? in other works is it ok if i put a link or small cedit to you to say something like this was made with the help of FtB?


cheers
0
fritz_the_blankCommented:
Sure,

Please link to www.FairfieldConsulting.com

Thanks,

Fritz the Blak
0
Rawdon HumeDeveloperAuthor Commented:
hi,

soz for the late reply,

ill put ur name and link in the links section of the web site when i have made it


thanks again for all your help

cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.