Click to See Complete Forum and Search --> : Sound preloaded with java applet


Laczeee
November 6th, 2004, 03:59 PM
I try to dowlnoad some wav files using a java applet. Everything works fine, the sounds get downloaded(they are playable) but after this I call the actual HTML page for which the pre-downloads were made for. When it gets loaded, it does not find the wavs cached so everything has to be re-downloaded again. I guess this means applets do not cache sounds. Is there a solution to repair the applet so that it could really pre-cache the wavs?

Here's the thread I use for downloading:


class LoadThread extends Thread
{
LoadThread(){};

public void run()
{
for (int i=1;i<=5;i++)
{
AudioClip s1;

switch (i)
{
case 1:s1=getAudioClip (getCodeBase(), "pinball.wav");break;
case 2:s1=getAudioClip (getCodeBase(), "ramy.wav");break;
case 3:s1=getAudioClip (getCodeBase(), "flyaway.wav");break;
case 4:s1=getAudioClip (getCodeBase(), "castle.wav");break;
case 5:s1=getAudioClip (getCodeBase(), "spencer.wav");break;
}

clipno=i;// I use clipno as a global variable in the paint() method

repaint();

try
{
sleep(0);
}
catch (InterruptedException e) {}
}
// after it finishes the for loop it loads the HTML file:
try
{
getAppletContext().showDocument(new URL("http://www.mrvarga.go.ro"), "_top");

}
catch (MalformedURLException ex)
{
ex.printStackTrace();

}
}

Joe Nellis
November 6th, 2004, 06:52 PM
...but after this I call the actual HTML page for which the pre-downloads were made for.
What do you mean by this? The browsers cache is different from the java plug-in's cache.

Laczeee
November 6th, 2004, 08:12 PM
You mean there's no way I could get the wavs in the browser's cache... (or it would be too complicated to do so). OK, I understand.

Then how could I predownload the sounds? I've tryed some scripting but it did not work out: I was unable to check when the download was complete. :(

Joe Nellis
November 7th, 2004, 03:17 AM
There are ways to access javascript from java and vice versa but a better question is what are you trying to do? Who really needs the wav files, the applet or the javascript. There are methods in javascript to preload files while the user is initially taking in the page.

Laczeee
November 7th, 2004, 04:22 AM
I need the wavs in HTML file. I could not integrate a working script in it, which would preload sounds (just like images).That is why I tried to fix the problem with an applet, because I could make a beautiful progress bar and everything in it :).

In the script I could only switch the bgsound's surce, but I could never see if the target sound was actually downloaded. The result was that I switched the src of every sound that I wanted to preload, one after the other, and only the last one got downloaded. (The idea was to download one completely, move to the next one download that one, and so on).

For better understanding, here's the address (the site is in hungarian, but I think you can get the idea. The links do not work yet anyway, because I only concentrated on the music player part)
http://www.mrvarga.go.ro

P.S. It only works correctly with iexplorer yet. :(