Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem w/ slick2d Sound  (Read 1012 times)
0 Members and 1 Guest are viewing this topic.
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Coding with bad posture since 2011... Nonstop.


« Posted 2013-06-22 18:05:17 »

I have googled at least a million times, and not found anything that works. I get this error:
1  
Failed to load: java.io.BufferedInputStream@3227f076

From this line of code:
1  
this.hurtSounds = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("res/sounds/zhurt0.wav"));


What is going on?

EDIT:
hurtsound is an Audio

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #1 - Posted 2013-06-22 19:05:06 »

This is simply not being able to find the file. make sure you have "res" in your class path.

Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Coding with bad posture since 2011... Nonstop.


« Reply #2 - Posted 2013-06-22 19:10:23 »

The hierarchy goes like this:

             |||THE ABOVE ALL PROJECT FOLDER|||
res            | bin              |  src              | .classpath, .project, etc.
sounds       | All class files |  All java files  |
hurtsounds  |                  |                    |

Is this the problem?

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Troncoso

JGO Coder


Medals: 20



« Reply #3 - Posted 2013-06-22 19:20:10 »

If I'm not mistaken, the InputStream is going to be looking in src/res/sounds/ for your audio, which clearly doesn't exist. As ra4king said, putting res in your class path should allow the InputStream to search in res as well.

That, or you can place your res folder in src. That should work with the code you've written.
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Coding with bad posture since 2011... Nonstop.


« Reply #4 - Posted 2013-06-22 19:20:59 »

Where is the classpath?

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Coding with bad posture since 2011... Nonstop.


« Reply #5 - Posted 2013-06-22 19:37:37 »

I put it in, and still the same error.  Sad

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #6 - Posted 2013-06-22 19:37:57 »

The classpath is whatever you define it to be but the default is the current directory: "src". Since "res" is outside that, the JVM does not know where it exists.

You have two options:
- move the "res" folder under "src" and it will work
- put "res" in the classpath and remove "res/" from the file path.

I recommend the first option.

Offline Troncoso

JGO Coder


Medals: 20



« Reply #7 - Posted 2013-06-22 20:05:20 »

If you are using Eclipse, you can right-click the project, go to configure build path, and go to the source tab. There you'll see the src folder because it's in your class path. You can click the "Add Folder..." button to add your res folder.

It should be similar in other IDE's. If you are using a regular text editor, I'm not really sure how you'd do it.
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Coding with bad posture since 2011... Nonstop.


« Reply #8 - Posted 2013-06-23 04:16:06 »

Still getting :
1  
could not get audio input stream from input stream


and
1  
Failed to load sound: res/sounds/zhurt0.wav


After taking this advice :
If you are using Eclipse, you can right-click the project, go to configure build path, and go to the source tab. There you'll see the src folder because it's in your class path. You can click the "Add Folder..." button to add your res folder.

It should be similar in other IDE's. If you are using a regular text editor, I'm not really sure how you'd do it.

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline philfrei
« Reply #9 - Posted 2013-06-23 05:38:53 »

In the very first post, it looks to me like your code is using in the same folder as the one where the class AudioLoader sits as the base folder.

If ResourceLoader is in 'src' then the code is looking in src/res/... etc., which doesn't exist. From your diagram, it looks like /res is a neighbor to /src. Yes?

Thus, maybe "../res/sounds/zhurt0.wav" would work.

*******

BUT it looks like you tried the valid alternative suggestion of putting res in the src folder and got a new error message. The new message mentions "input stream" which reminds me of an error which surfaced in Java 7 and caused me a fair bit of grief to figure out.

In Java7's audio library (javax.sound.sampled.*), if you try to load a wav to an InputStream, and then load the InputStream to an AudioInputStream, you will likely generate a "Mark/Reset" error, because wav files are not usually markable and resetable (a requirement of InputStreams). Fortunately, Java Audio lets you load an AudioInputStream directly from a File or URL directly, rather than from an InputStream.

Since the error mentions being unable to read from the InputStream, I am wondering if the code is creating an intermediate "InputStream" that is generating the Mark/Reset error.

So, I do a quick search on "ResourceLoader Slick" and see that that the code you are using is standard Slick library stuff. Since this is a standard Slick usage example, scratch that idea. I would be really surprised if the coders of a well-used library like Slick hadn't accounted for this known error. (I hope that little digression wasn't too unhelpful.)

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #10 - Posted 2013-06-23 06:11:03 »

No no no the error is that OP did not read my post. I'll re-paste it here:

Quote
The classpath is whatever you define it to be but the default is the current directory: "src". Since "res" is outside that, the JVM does not know where it exists.

You have two options:
- move the "res" folder under "src" and it will work
- put "res" in the classpath and remove "res/" from the file path.

I recommend the first option.

By default, ResourceLoader looks in "src". If you add "res" to the classpath, it also looks in "res". When you specify path "res/sounds/zhurt0.wav", it's looking for a folder named "res" INSIDE of "src" and "res", neither of which contain said folder. This is why you should have read option 2: put "res" on the classpath and remove "res/" from the file paths (notice the first forward slash is also included). However, I recommend the first option where you simply move the "res" folder and put it inside "src", which will require no renaming of paths.

Offline davidc

Senior Member


Medals: 5
Projects: 2



« Reply #11 - Posted 2013-06-23 07:14:20 »

This might sound a bit pedantic, but I think we're getting confused about where "src" fits into the classpath. Typically it isn't part of the classpath at all. Normally it is a destination folder called "classes" where all the compiled classes end up.

Most IDEs also have the option of recognising other "source" folders. The contents of these folders (ig. "res" for your resources) are also copied to the destination "classes" folder.

The classloader used by ResourceLoader will most certainly be looking in this "classes" folder for the files. I would be checking there to see if the file exists. This is the reason why making a distinction between "src" and the classpath is important - depending on the type of file and your IDE, the contents of a source folder might not be getting copied to the destination classes folder. It may also be getting put in a folder in classes that does not necessarily mirror the structure in src.

To make debugging this a lot easier I would suggest breaking up the line loading the resource into two. Perhaps even add some additional checking. For example:

1  
2  
3  
4  
5  
6  
7  
String resourcePath = "res/sounds/zhurt0.wav";
InputStream in = ResourceLoader.getResourceAsStream(resourcePath);
if (in == null) {
  throw new IOException("The resource " + resourcePath + " does not exist at the expected location");
}

this.hurtSounds = AudioLoader.getAudio("WAV", in);


It would have more convenient had the ResourceLoader class performed this checking for you an raised an appropriate exception. I'm not too keen on code that just returns a null on failure. Exceptions do this job so much better.
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Coding with bad posture since 2011... Nonstop.


« Reply #12 - Posted 2013-06-23 14:57:55 »

No cp right now, so ill try all this later. Thanks!

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline philfrei
« Reply #13 - Posted 2013-06-24 00:44:00 »

@davidc - The discussion on class path and src is good. But the example you gave will very likely return the "Mark/Reset" error I brought up, won't it? InputStreams are required to be markable and resetable, and wav files generally are not.

@r4king - I couldn't tell for sure what the op meant by "I put it in and still the same error." Aren't pronouns great! I assumed he had followed your original suggestion of moving res into src (put 'res' into 'src') and then got the new error message.

***

I don't have Slick installed. Can anyone verify that the code davidc posted works without causing the Java7 "mark/reset" error? I'm really curious to know for sure.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline davidc

Senior Member


Medals: 5
Projects: 2



« Reply #14 - Posted 2013-06-24 03:29:19 »

If the file is being found (which we still don't know for sure either way), then the issue might indeed be the mark/reset issue. I'm actually thinking the assumption that this is a classpath issue might be a little off given the error message:
1  
Failed to load: java.io.BufferedInputStream@3227f076

This seems to indicate that an input stream was instantiated.

This is the advantage of splitting the code up into separate lines rather than cramming it all together. It's much easier to identify what exactly causes the problem, rather than making assumptions.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (37 views)
2014-04-15 18:08:23

BurntPizza (33 views)
2014-04-15 03:46:01

UprightPath (49 views)
2014-04-14 17:39:50

UprightPath (31 views)
2014-04-14 17:35:47

Porlus (48 views)
2014-04-14 15:48:38

tom_mai78101 (69 views)
2014-04-10 04:04:31

BurntPizza (129 views)
2014-04-08 23:06:04

tom_mai78101 (229 views)
2014-04-05 13:34:39

trollwarrior1 (193 views)
2014-04-04 12:06:45

CJLetsGame (200 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!