Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Playing sound from a jar file

 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • 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
MyEclipse IDE Firefox Browser Linux
  • 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.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic