• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Playing sound from a jar file

 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic