Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
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  
  Exporting Jar with OpenAL  (Read 3240 times)
0 Members and 1 Guest are viewing this topic.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Posted 2013-12-16 14:30:56 »

I have a exported Jar that loads WAV files through this method:
1  
2  
3  
4  
5  
6  
7  
8  
9  
public void loadSound(String path) throws FileNotFoundException {
      WaveData data = null;
      data = WaveData.create(GameSound.class.getClassLoader().getResourceAsStream(path));
      int buffer = alGenBuffers();
      alBufferData(buffer, data.format, data.data, data.samplerate);
      data.dispose();
      source = alGenSources();
      alSourcei(source, AL_BUFFER, buffer);
   }

The sound files I'm trying to load are in the same package as the class that the above method is in. I've tried to use all sorts of ways to load the WaveData, but none of them work after exporting; they all return a NPE or file not found. Has anyone here used OpenAL? How do I get the files in the same package after exporting? I guess this is a newbie issue because it is just file handling, but I never took the time to learn the difference between a lot of the Java IO functions...

Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2013-12-16 14:53:39 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
[code]Well, I tried this:
[code]
public void loadSound(String path) {
      InputStream is = GameSound.class.getResourceAsStream("sound" + File.separatorChar + path);
      System.out.format("is " + path + "  null ? => %s", is == null);
      System.out.println();
      WaveData data = WaveData.create(is);
      int buffer = alGenBuffers();
      alBufferData(buffer, data.format, data.data, data.samplerate);
      data.dispose();
      source = alGenSources();
      alSourcei(source, AL_BUFFER, buffer);
   }

Again, it works fine in Eclipse but not after exporting.

Edit:
Tried this way now, still doesn't work. I guess this thread is just going to turn into a personal log of failure...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public void loadSound(String path) {
      URL is = GameSound.class.getResource("sound" + File.separatorChar + path);
      System.out.println(is.getPath());
      System.out.format("is " + path + "  null ? => %s", is == null);
      System.out.println();
      WaveData data = WaveData.create(is);
      int buffer = alGenBuffers();
      alBufferData(buffer, data.format, data.data, data.samplerate);
      data.dispose();
      source = alGenSources();
      alSourcei(source, AL_BUFFER, buffer);
   }


Edit: With this code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
public void loadSound(String path) {
      InputStream is = GameSound.class.getClassLoader().getResourceAsStream("com" + File.separatorChar + "nishu" + File.separatorChar + "ld28 "  + File.separatorChar + "utilities" + File.separatorChar + "sound" + File.separatorChar + path);
      WaveData data = WaveData.create(is);
      int buffer = alGenBuffers();
      alBufferData(buffer, data.format, data.data, data.samplerate);
      data.dispose();
      source = alGenSources();
      alSourcei(source, AL_BUFFER, buffer);
   }

I get a NPE with this line:
1  
      alBufferData(buffer, data.format, data.data, data.samplerate);

Maybe I'm getting somewhere? I don't think so though.[/code][/code]

Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #2 - Posted 2013-12-16 15:07:56 »

I know I'm being annoying but this is for Ludum Dare which ends in just a few hours and I just can't get OpenAL to load the damn files... I have tried countless things and now I really need help.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #3 - Posted 2013-12-16 15:43:47 »

Well, I got it to work. I had to put all the classes and music files in the default package. Now though, it doesn't load two of my sound files. It just says the system cannot find the file specified in the exported Jar, but it works in Eclipse. grr.

Offline alesky

Junior Member


Medals: 3
Exp: 15 years


mmm....


« Reply #4 - Posted 2013-12-16 17:36:34 »

Class loader issue my friend

dont' blame on OpneAL

all the issue is related to this line of code
GameSound.class.getResourceAsStream("sound" + File.separatorChar + path);

question what is the class loader that load the class GameSound?
for sure is not the same where is loaded the resource "sound" + File.separatorChar + path

it works in eclipse because it load all the resources of the project in the same classpath

and what you mean to export the jar?
are you executing the main class with command line?
if you will run the class by command line and will add with option -cp or -classpath all the jar, it will works

this is an example
java -cp ../lib/application.jar;../other.jar;../config com.x.y.z.MainClass

./config is a folder if you wont to add file as images configuration file wave file etc directly in file system withtou bind in a jar

i suppose that you create an executable jar correct?

another important point is the definition of the resource name that is different if call in the
getResourceAsStream in the ClassLoader or Class

this is the correct sintax (look the char / based on object that call the method getResourceAsStream)
ClassLoader.getResourceAsStream("some/pkg/resource.properties");
Class.getResourceAsStream ("/some/pkg/resource.properties");







Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #5 - Posted 2013-12-16 21:26:39 »

I figured it out, don't mind me. But I still wonder why some sounds don't play... Oddly enough they were my two background sounds. They were perfectly fine in Eclipse but when I exported the Jar they stopped playing. Does OpenAL have a size limit? Because the one file I was trying to play was 14 MB. The other file was only 4 MB, so I don't think that's the issue.

Another problem I found was that sounds wouldn't play exactly when I called them to start, which really annoyed me. For instance, when the player dropped to a certain health level I call on a heartbeat sound to start playing. It doesn't play until I pause the game though, and then stops when I unpause it. I had other sounds playing at the other time, so maybe that was the issue? Either way its kind of annoying that a sound library just doesn't work as its supposed to...

Offline alesky

Junior Member


Medals: 3
Exp: 15 years


mmm....


« Reply #6 - Posted 2013-12-17 14:06:35 »

I figured it out, don't mind me. But I still wonder why some sounds don't play... Oddly enough they were my two background sounds. They were perfectly fine in Eclipse but when I exported the Jar they stopped playing. Does OpenAL have a size limit? Because the one file I was trying to play was 14 MB. The other file was only 4 MB, so I don't think that's the issue.

regarding this point if it works in eclipse it works outside eclipse, i mean if size limit exist, exist inside and outside!
so again i ask you an important question, what you mean for
" I exported the Jar " ?
can you explain how i structured your deployment version of your project in the way that may be will be more easy help you to find a solution and explain why it is not working outside eclipse?

did you try to start the project with command line?
do you have the same behavior?



Another problem I found was that sounds wouldn't play exactly when I called them to start, which really annoyed me. For instance, when the player dropped to a certain health level I call on a heartbeat sound to start playing. It doesn't play until I pause the game though, and then stops when I unpause it. I had other sounds playing at the other time, so maybe that was the issue? Either way its kind of annoying that a sound library just doesn't work as its supposed to...

this instead is related to another issue,
from you description look like that the thread that manage the sound start only when the thread that manage the game is stopped
may be in this case try to attach code to understand whats is happening
(anyway for this other question may be is better to create a different thread in the forum)



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.

CopyableCougar4 (14 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!