Solved

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

Posted on 2003-12-07
29
583 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:Rawdon Hume
  • 15
  • 14
29 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
<EMBED NAME="mySound" SRC="mySound.mid"
LOOP=FALSE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND>

FtB
0
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
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
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
also where in the code u give me do i put sound file name "music.mp3" ?

cheers
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
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
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
<EMBED NAME="Bach" SRC="music.mp3"
LOOP=FALSE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND>
0
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
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
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
hi,

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

thank you
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
I just tried it and it works fine for me--it takes a little time to load, however.

FtB
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 255 total points
Comment Utility
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
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
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
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
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
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
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
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
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
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
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
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
hi,

any idea how to fix the problem????

cheers
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
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
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
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
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
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
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
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
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
The tripod link starts the music straight away.

FtB
0
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
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
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
I don't understand...

FtB
0
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
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
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Good luck with your project,

FtB
0
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
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
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Sure,

Please link to www.FairfieldConsulting.com

Thanks,

Fritz the Blak
0
 
LVL 2

Author Comment

by:Rawdon Hume
Comment Utility
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now