Click to See Complete Forum and Search --> : Preloading Sound


Timbuck2
02-23-2003, 03:53 AM
is There a way I can preLoad Sound. ( so it does not comes across the wire twice, and so that it plays as rapidly as possibly)

I have a background sound which is a midi file.
and about 30 special effects sounds.
I wan all the special effects sounds immediately available.

I made an array of 50 bgSounds. Each sound maintains it duration. after it's duration I flag the soundbank as being available to play another sound.

this allows several sounds to play at the same time which works great.

Sometimes I get a pause and I notice that the sounds are reloading.

I copied my code to my server and just opened it in a browser.

It appears
the midi file - loads to my workstation and starts playing ( but the local hard drive lite does comes on ferquently)

The sound effects which are waves, When these activate the lite on my network card comes on as if the sounds are coming across the wire again.

Does anyone know how to do this ?

Nevermore
02-23-2003, 04:45 AM
In the body of your document, put:
<embed SRC="source" HIDDEN=true AUTOSTART=false> for each of your sounds. This will load them, but not play them. I find it works best if you put this at the end of your document.

Then, to play each of them, use:
document.embeds[number].play();

where number is the number of your sound, counting down from the top, in order as printed in the source.

Timbuck2
02-23-2003, 04:49 AM
Thank you very much. I'm off to fix that right up.
Thanks again.

Timbuck2
02-23-2003, 08:16 AM
grrr. I appreciate your advice unfortunately this slowed my applications "capabilities" down further. It chokes because it no longer has a buffer of sound threads. I guess I'll tune it with several static instances of each sound. My app plays 1 to 50 sounds at a given instant some of the sounds are the same sound though offsets by milliseconds. So when I play the sound again it resets the one that was playing. (the way I just changed it)

So anyway I can tune that part with early bound [embeded] instances (several for each sound)

That will fix the Speed issue
but

The weird thing is I still find it is accessing the server. When I activate the code for the sounds.
I realize this normally isn't done. But,if anyone has a clue please post. For now. I need sleep.

Nevermore
02-23-2003, 08:45 AM
It is accessing the server to download the sounds.

Timbuck2
02-23-2003, 07:47 PM
Please bare with me on this one.
I've tried various methods to preload images and sounds. I'm just getting weird test results.

heres one of many tests.

var oImage = new Image(50,60)

function test1()
{oImage.src="myImage.gif"
}

when I activate test1 no data comes across the wire.
when I set an img tags src attribute to oImage.src then data comes which is what I do not want.
same with wav and mid file.
----------------
I'm hoping someone might have the time to write a short correct snippet. along these lines. and comfirm it works So that I can determine why the heck I cant do it. I know this is something simple I'm just not seeing.


[Global]
var mImg = new Image()
var mSound = new Image()

function testLoad()
mImg.src = "myImage"
mSound.src = "mySound"

function testAssignImage()
document.getElementById("someImage").src = mImg.src

function testPlaySound()
document.getElementById("something").src = mSound.src

Timbuck2
02-24-2003, 11:15 AM
What I have learned thus Far.
Using IE 6 as a Browser to test.

1. The statement Var i = new Image();i.src="some.jpg"
does not preload anything, howevere new Image will
or new Image(90,90)
2. Embeds - when you embed 2 files and use the play() method on both only one will play and there is no gaurantee which it will be.
3. an Array of bgSounds will allow you to fire multple simultaneous sounds but each comes acrosss the wire when you set there source.
4. next test - load the sounds with new Image - no brackets
and new Image(10,10) -- an arbitrary set of numbers.

and use BgSound to allow an array of sounds.