Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (748)
Games in Android Showcase (226)
games submitted by our members
Games in WIP (834)
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  
  Paul's SoundSystem, set folder for files  (Read 65923 times)
0 Members and 1 Guest are viewing this topic.
Offline jakethesnake

Senior Devvie


Medals: 5
Projects: 1



« Posted 2015-08-07 07:35:48 »

So, I want to keep my sound-files outside of my jar, in a folder res.

Paul allows one to choose a package inside the Src folder, like this:

1  
SoundSystemConfig.setSoundFilesPackage("Sound");


But I can't get outside of the src folder!

Does anyone know how to do this?

Oh, and by the way, I've fixed Pauls LWJGL-jar so that it runs with LWJGL 3.0 if anyone is interested!
Offline Jesse

JGO Coder


Medals: 23



« Reply #1 - Posted 2015-08-07 11:47:21 »

I'm not familiar with the library, but according to the documentation there's a loadSound() function that takes a URL. Have you tried this with a URL representing a path to one of your files? Assuming the library is open-source, perhaps you could also find the location in the code where the loading occurs and see if accessing files outside the JAR is supported. (Or, perhaps you could just ask the developer directly.)

Also, may I ask why you want to keep your resources outside the JAR? I'm not saying you shouldn't, but knowing what your goals are might help. (My understanding is that loading resources from JARs is generally preferable though - for one thing, it sidesteps some potential issues with the location of the current working directory and/or acquiring the absolute path to your external resources folder.)
Offline jakethesnake

Senior Devvie


Medals: 5
Projects: 1



« Reply #2 - Posted 2015-08-07 12:10:33 »

In the javadoc he says that URL's are used only to load resources from the internet. I am quite unfamiliar with the use of URL's. Don't know exactly what they are... But I could try.

My res folder is still in the project folder, so I can use relative paths I think. I like to keep it this way, since my game is getting rather big and the src folder is cluttered with packages as it is and I like to keep a distinction between files and code.

How would one go about using an URL for this purpose?

I've got the following folder structure:

Game
     src
     res
         sound
    
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2015-08-08 13:43:12 »

Oh, and by the way, I've fixed Pauls LWJGL-jar so that it runs with LWJGL 3.0 if anyone is interested!
Contact Paul, send him a nice patch  Grin

Julien Gouesse | Personal blog | Website | Jogamp
Online philfrei
« Reply #4 - Posted 2015-08-09 21:43:31 »

There are two different forms for locating folders for a project, depending on whether you start the location with a "/" or not. Using the "/" is an absolute address that starts from the code base, otherwise the location is relative to the location of the class that is used for the call. I'm assuming the form getResource(filename) or getResourceAsStream(filename).

The symbol ".." is useful for backing up one level.

In general URL's are more reliable, since the file system is unable to locate files embedded in a jar. URL = Uniform Resource Locator. The JavaDocs for URL has more info.

I've got the following folder structure:

Game
     src
     res
         sound
If you have a Class called PlaySound in folder src, and res is a "neighboring" folder (as in your diagram), you should be able to use the following.

1  
URL url = PlaySound.class.getResource("../res/sound");


I did a test where my structure was the following:

jgoQuestions  // a package in the Eclipse project
    res
         foo.txt
    src
         ResourceTest

From here, the following worked (running the class ResourceTest):
1  
2  
URL url = ResourceTest.class.getResource("../res/foo.txt");  // relative form
URL url = ResourceTest.class.getResource("/jgoQuestions/res/foo.txt");  //absolute form

music and music apps: http://adonax.com
Offline jakethesnake

Senior Devvie


Medals: 5
Projects: 1



« Reply #5 - Posted 2015-08-11 07:29:54 »

Thanks!

I put all your advice together and solved it this way:

this is the structure:

folder MyGame
      src
          Sound.java
      res
          sound
                shout.wav     

in Sound.java:
1  
2  
3  
4  
String path = "res/sound/shout.wav";
URL url = new File(path).toURI().toURL;

SoundSystem.newSource(URL....);


Don't know if this is bad practise or not, but it works!

Offline Jesse

JGO Coder


Medals: 23



« Reply #6 - Posted 2015-08-11 08:32:27 »

Don't know if this is bad practise or not, but it works!

If I'm not mistaken (and I may be), that solution relies on the current working directory being your game folder, which may or may not be the case depending on how and from where your app was run. Whether this matters depends, I suppose, on how you intend to distribute the app, but in my experience the working directory may end up elsewhere in some deployment scenarios. Anyway, just something to keep in mind.
Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (332 views)
2017-12-31 17:17:51

xxMrPHDxx (109 views)
2017-12-31 17:15:51

xxMrPHDxx (158 views)
2017-12-28 18:11:33

Ecumene (340 views)
2017-09-30 02:57:34

theagentd (504 views)
2017-09-26 18:23:31

cybrmynd (548 views)
2017-08-02 12:28:51

cybrmynd (487 views)
2017-08-02 12:19:43

cybrmynd (461 views)
2017-08-02 12:18:09

Sralse (423 views)
2017-07-25 17:13:48

Archive (1346 views)
2017-04-27 17:45:51
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!