473,378 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Retrieving Sounds from a Jar file

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
6 3183
"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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Ryan Stewart | last post by:
I am in extremely urgent need (by tomorrow) of a way to store files in and retrieve files from an Oracle database using TopLink as an intermediary. I have the JSPs for it, and it works for small...
1
by: Dave Rams | last post by:
Can some one suggest an article on the saving and retrieving VB.net projects. I have lost complete programs at least twice. I have to reconstruct the programs. It has happened when I enter...
1
by: Roman Kagan | last post by:
Hi everyone, I am successful in retrieving the image from the table (.TIF), however, the retrieved file does not work. It looks like an image file - extension, size and all, but the image is not...
0
by: hsifelbmur | last post by:
We are writing an app that automates printing of documents of different types. These documents are printed to PostScript files, not to a printer. The app uses shellExecute with the "printto" verb...
0
by: Eidolon | last post by:
I was working on one of my assemblies yesterday which we have in our GAC and is used by a number of our web applications/sites on our intranet. Something strange started happening though. I would...
0
by: kid4rilla | last post by:
I can successfully write the binary data to an image data type, and successfully retrieve it, but when I attempt to play the file in media player after retrieving it, I get the file type isn't...
2
by: shivapadma | last post by:
i have inserted the image into database using the following code String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/"; String dbName =...
1
by: michels287 | last post by:
Hello... Currently I have an array of 8 listboxes in VB6. Each item in my listbox plays a wav sound from a large file on my desktop called "Sounds". I am using the sndPlaySound API. The code I...
1
by: Enij | last post by:
Hi All, I'm using VB.net 2003 Standard Edition, and I'm trying to retrieve the file modified date. Sounds painfully simple. Yup. But ... I cannot, for the life of me, figure it out. After...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.