[Logo]
Forums Register Login
Playing sound from a jar file
I am having problems trying to access sound resources from my jar file. They reside in the directory "/sounds/" in the jar. I am not able to point to the sound file from my code using a URL.



When i run the code outside of the jar everything is fine. But when i put everything into a jar the URL class is unable to reach the wav file. I have the jar in my classpath. A work around could be to use

AudioClip clip = Applet.newAudioClip(url);
clip.play();

But thats not a solution here because once i switch to clip.play() instead of using audio input stream the audio does not play sometimes when called in quick successions or it waits a long time ( around 2 seconds ) before it plays the clip. Does any one know a way through which i can still access the wav files using an audio input stream ? Or can you suggest a way through which i can improve the performance of clip.play() ?

Any suggestions are welcome.
Hey i figured it out ! I am able to stream sound files with the following code.



Just posting to let people know about this solution.

This thread has been viewed 3024 times.

All times above are in ranch (not your local) time.
The current ranch time is
Dec 19, 2018 04:33:45.