Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Waiting for audioClip to finish loading.

Status
Not open for further replies.

Nalgene

Technical User
Apr 22, 2006
8
CA
Hi everyone,

I have an applet and I want it to have a background midi file. I've so far implement the classes found on Sun's site AppletSoundList and AppletSoundLoader.

This is working well if I give it enough time to load the midi before starting it...so far I've been doing that using a simple Thread.sleep...this obviously won't work once I deploy online since the clients connection speed will vary and a fixed Thread.sleep will not be optimal.

I've looked into MediaTracker but it seems like it doesn't support audio, only images...is there a way using the two class I have to tell the applet to wait for the audio clip? I was going to start the loop in the start() method but obviously if the sounds isn't loaded that will cause a problem...

Thanks a bunch if you can help! I would really appreciate it.
 
Well, I've fixed it myself after a coffee and much thinking :)

Since the search didn't bring up anything I'll post my solution here and hopefully it can help others that could use the search feature in the future.

Basically I had no idea what I was doing when I started looking into how to implements sounds on a JApplet. I used the first doc I found which was from Sun's website. That method loads the ressources in a seperate Thread because it exactly doesn't want to force the client to wait for the files to load. It is not designed for a background music, cause if you want a music file right when you load up you WANT to lock the user from the Applet while the ressources download.

Simply using :
nameOfAudioClipObject = this.getAudioClip(this.getCodeBase(), "nameOfFile");

nameOfAudioClipObject.loop();

in start() will wait for the ressource to be downloaded to the client before resuming...

TO me this seems like the best way to go, I'm relatively new to Java though so if there's a better way, please post about it I would love to learn it.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top