By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 1,607 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

Retrieving Sounds from a Jar file

P: n/a
Hello!

In our game package (www.andromedaonline.net) we are having problems with
sounds. We have placed them in a jar file, and are trying to access them
from there.

The jar file has a directory structure. A number of sounds have the same
name, but are in a different directory (for example, our game has 5 races.
Each race has the same set of sounds- button clicks, etc, but the actual
sound is different).

We've attempted doing this (for buttonClickSound, made when a player hits a
button):

soundJar = new JarResources("AndromedaSFX.jar");
URL clickSoundURL = new
URL(soundJar.getResource("/com/Andromeda/sounds/main/Main-click.wav"));
buttonClickSound = Applet.newAudioClip(clickSoundURL);

However soundJar.getResource returns BYTE and we need STRING in the above
example. we replaced "clickSoundURL" with:

URL clickSoundURL = PreGamePanel.class.getResource("Main-click.wav");

but that returns a null pointer exception (presumably because I don't have
the directory structure... Nor do I know how it's supposed to know which jar
file to get the file from in the second example).

Nobody here has any experience with accessing .wav files from a jar file. We
would greatly appreciate any help one could offer.

Thank you for your time.

Nick Soutter

Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"BlackHawke" <bl********@legacygames.net> wrote in message
news:jt******************@newsread1.news.pas.earth link.net...
Hello!

In our game package (www.andromedaonline.net) we are having problems with
sounds. We have placed them in a jar file, and are trying to access them
from there.

The jar file has a directory structure. A number of sounds have the same
name, but are in a different directory (for example, our game has 5 races.
Each race has the same set of sounds- button clicks, etc, but the actual
sound is different).

We've attempted doing this (for buttonClickSound, made when a player hits a button):

soundJar = new JarResources("AndromedaSFX.jar");
URL clickSoundURL = new
URL(soundJar.getResource("/com/Andromeda/sounds/main/Main-click.wav"));
buttonClickSound = Applet.newAudioClip(clickSoundURL);

However soundJar.getResource returns BYTE and we need STRING in the above
example. we replaced "clickSoundURL" with:

URL clickSoundURL = PreGamePanel.class.getResource("Main-click.wav");

but that returns a null pointer exception (presumably because I don't have
the directory structure... Nor do I know how it's supposed to know which jar file to get the file from in the second example).

Nobody here has any experience with accessing .wav files from a jar file. We would greatly appreciate any help one could offer.

Thank you for your time.

Nick Soutter


Did you google this before posting? Seems to me I researched this same thing
not long ago and found some good suggestions in the archives. Search for
"getImageFromJar". I think that's what I found. It should be easily
adaptable to any file type.
Jul 17 '05 #2

P: n/a
We have checked Google, AltaVista, and Java.sun.com

We successfully get many graphics files from our jar file.

The problem is that because the Applet.newAudioClip method requires a
url/string, the same method to obtain graphics from a jar file can not be
used here. The graphics methods (which use "getResource"- included in my
sample) can not return strings.

Thanks for the thought, though. :(

Nick Soutter

"Ryan Stewart" <zz********@gSPAMo.com> wrote in message
news:cM********************@texas.net...
"BlackHawke" <bl********@legacygames.net> wrote in message
news:jt******************@newsread1.news.pas.earth link.net...
Hello!

In our game package (www.andromedaonline.net) we are having problems with sounds. We have placed them in a jar file, and are trying to access them
from there.

The jar file has a directory structure. A number of sounds have the same
name, but are in a different directory (for example, our game has 5 races. Each race has the same set of sounds- button clicks, etc, but the actual
sound is different).

We've attempted doing this (for buttonClickSound, made when a player hits
a
button):

soundJar = new JarResources("AndromedaSFX.jar");
URL clickSoundURL = new
URL(soundJar.getResource("/com/Andromeda/sounds/main/Main-click.wav"));
buttonClickSound = (clickSoundURL);

However soundJar.getResource returns BYTE and we need STRING in the
above example. we replaced "clickSoundURL" with:

URL clickSoundURL = PreGamePanel.class.getResource("Main-click.wav");

but that returns a null pointer exception (presumably because I don't have the directory structure... Nor do I know how it's supposed to know which

jar
file to get the file from in the second example).

Nobody here has any experience with accessing .wav files from a jar

file. We
would greatly appreciate any help one could offer.

Thank you for your time.

Nick Soutter
Did you google this before posting? Seems to me I researched this same

thing not long ago and found some good suggestions in the archives. Search for
"getImageFromJar". I think that's what I found. It should be easily
adaptable to any file type.

Jul 17 '05 #3

P: n/a
BlackHawke wrote:
Hello!

In our game package (www.andromedaonline.net) we are having problems with
sounds. We have placed them in a jar file, and are trying to access them
from there.

The jar file has a directory structure. A number of sounds have the same
name, but are in a different directory (for example, our game has 5 races.
Each race has the same set of sounds- button clicks, etc, but the actual
sound is different).


I think you're looking for the jar URL hack. It looks like this:
jar:http://www.xxx.yyy/jarfile.jar!/mypackage/myclass.class
That's a URL meaning "fetch http://www.xxx.yyy/jarfile.jar and look inside
for a file called /mypackage/myclass.class". Of course the inner URL could
just as well be a local file.

This thing is so ugly I prefer not to talk about it too much. Enjoy.

--
Chris Gray ch***@kiffer.eunet.be
/k/ Embedded Java Solutions

Jul 17 '05 #4

P: n/a
BlackHawke wrote:
Hello!

In our game package (www.andromedaonline.net) we are having problems with
sounds. We have placed them in a jar file, and are trying to access them
from there.

The jar file has a directory structure. A number of sounds have the same
name, but are in a different directory (for example, our game has 5 races.
Each race has the same set of sounds- button clicks, etc, but the actual
sound is different).

We've attempted doing this (for buttonClickSound, made when a player hits a
button):

soundJar = new JarResources("AndromedaSFX.jar");
URL clickSoundURL = new
URL(soundJar.getResource("/com/Andromeda/sounds/main/Main-click.wav"));
buttonClickSound = Applet.newAudioClip(clickSoundURL);

However soundJar.getResource returns BYTE and we need STRING in the above
example. we replaced "clickSoundURL" with:

URL clickSoundURL = PreGamePanel.class.getResource("Main-click.wav");

but that returns a null pointer exception (presumably because I don't have
the directory structure... Nor do I know how it's supposed to know which jar
file to get the file from in the second example).

Nobody here has any experience with accessing .wav files from a jar file. We
would greatly appreciate any help one could offer.

Thank you for your time.

Nick Soutter


I think you've made this too complicated. Why not put the jar
containing the files in the classpath? Then use:

URL url = this.getClassLoader().getResource("/path/to/sound/file.au");

Ray
Jul 17 '05 #5

P: n/a
That did it, Thanks!!!
"chris" <ch***@kiffer.eunet.be> wrote in message
news:c0**********@reader08.wxs.nl...
BlackHawke wrote:
Hello!

In our game package (www.andromedaonline.net) we are having problems with sounds. We have placed them in a jar file, and are trying to access them
from there.

The jar file has a directory structure. A number of sounds have the same
name, but are in a different directory (for example, our game has 5 races. Each race has the same set of sounds- button clicks, etc, but the actual
sound is different).


I think you're looking for the jar URL hack. It looks like this:
jar:http://www.xxx.yyy/jarfile.jar!/mypackage/myclass.class
That's a URL meaning "fetch http://www.xxx.yyy/jarfile.jar and look inside
for a file called /mypackage/myclass.class". Of course the inner URL could
just as well be a local file.

This thing is so ugly I prefer not to talk about it too much. Enjoy.

--
Chris Gray ch***@kiffer.eunet.be
/k/ Embedded Java Solutions

Jul 17 '05 #6

P: n/a
It is in the classpath. :(

This has been tried, didn't work.

Nick
"Raymond DeCampo" <rd******@spam-I-am-not.twcny.rr.com> wrote in message
news:_k*******************@twister.nyroc.rr.com...
BlackHawke wrote:
Hello!

In our game package (www.andromedaonline.net) we are having problems with sounds. We have placed them in a jar file, and are trying to access them
from there.

The jar file has a directory structure. A number of sounds have the same
name, but are in a different directory (for example, our game has 5 races. Each race has the same set of sounds- button clicks, etc, but the actual
sound is different).

We've attempted doing this (for buttonClickSound, made when a player hits a button):

soundJar = new JarResources("AndromedaSFX.jar");
URL clickSoundURL = new
URL(soundJar.getResource("/com/Andromeda/sounds/main/Main-click.wav"));
buttonClickSound = Applet.newAudioClip(clickSoundURL);

However soundJar.getResource returns BYTE and we need STRING in the above example. we replaced "clickSoundURL" with:

URL clickSoundURL = PreGamePanel.class.getResource("Main-click.wav");

but that returns a null pointer exception (presumably because I don't have the directory structure... Nor do I know how it's supposed to know which jar file to get the file from in the second example).

Nobody here has any experience with accessing .wav files from a jar file. We would greatly appreciate any help one could offer.

Thank you for your time.

Nick Soutter


I think you've made this too complicated. Why not put the jar
containing the files in the classpath? Then use:

URL url = this.getClassLoader().getResource("/path/to/sound/file.au");

Ray

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.