Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
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  
  TinySound exporting issues  (Read 780 times)
0 Members and 1 Guest are viewing this topic.
Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Posted 2013-12-16 00:19:16 »

I'm using TinySound to play my OGG files, and when I go to export the Jar file and run it, TinySound throws this error:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
C:\Users\Toby\Desktop>java -jar xmasFear.jar
Unsupported audio resource!
could not get audio input stream from input URL
Unsupported audio resource!
could not get audio input stream from input URL
Unsupported audio resource!
could not get audio input stream from input URL
Unsupported audio resource!
could not get audio input stream from input URL
Unsupported audio resource!
could not get audio input stream from input URL
Unsupported audio resource!
could not get audio input stream from input URL
Unsupported audio resource!
could not get audio input stream from input URL
Unsupported audio resource!
could not get audio input stream from input URL

This is how I load my sounds:
1  
2  
3  
4  
5  
6  
7  
8  
9  
public static Music Horde = TinySound.loadMusic("sounds/zombie_horde.ogg");
   public static Music heartbeat = TinySound.loadMusic("sounds/heartbeat.ogg");
   public static Music xmas = TinySound.loadMusic("sounds/merry_xmas.ogg");
   
   public static Sound Bite = TinySound.loadSound("sounds/zombie_bite.ogg");
   public static Sound ZombieKilled = TinySound.loadSound("sounds/zombie_attacked.ogg");
   public static Sound itemPickup = TinySound.loadSound("sounds/item_pickup.ogg");
   public static Sound powerup = TinySound.loadSound("sounds/powerup.ogg");
   public static Sound hurt = TinySound.loadSound("sounds/player_hurt.ogg");

I know I need to do something different, obviously, but I don't know what. I think I need to use a classLoader, but how would I do that?

Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #1 - Posted 2013-12-16 01:30:45 »

So now I've tried this:
1  
2  
3  
4  
5  
public Music loadMusic(String path){
      URL url = GameSound.class.getClass().getResource(path);
      Music m = TinySound.loadMusic(url);
      return m;
   }

But it still can't find the resources in the export.

Offline philfrei
« Reply #2 - Posted 2013-12-16 02:07:06 »

Could you show the file structure, and where the audio files are located?

"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 opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #3 - Posted 2013-12-16 02:15:01 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
public class GameSound {
   
   public Music m;
   public Sound s;
   
   public GameSound(boolean sound, String path){
      if(!sound) m = loadMusic(path);
      else if(sound) s = loadSound(path);
   }
   
   private Sound loadSound(String path) {
      InputStream url = GameSound.class.getClassLoader().getResourceAsStream(path);
      Sound s = TinySound.loadSound(url.toString());
      return s;
   }

   public Music loadMusic(String path){
      URL url = GameSound.class.getClassLoader().getResource(path);
      Music m = TinySound.loadMusic(url);
      return m;
   }
   
   public void play(boolean sound, boolean loop, double volume){
      if(sound) s.play(volume);
      if(!sound) m.play(loop, volume);
   }
   
   public void stop(){
      if(m != null) m.stop();
      if(s != null) s.stop();
   }

This is how I load them:
1  
2  
3  
4  
5  
6  
7  
horde = new GameSound(false, "zombie_horde.ogg");
      item_pickup = new GameSound(true, "item_pickup.ogg");
      merry_xmas = new GameSound(false, "merry_xmas.ogg");
      player_hurt = new GameSound(true, "player_hurt.ogg");
      powerup = new GameSound(true, "powerup.ogg");
      zombie_attacked = new GameSound(true, "zombie_attacked.ogg");
      zombie_bite = new GameSound(true, "zombie_bite.ogg");

All of those are GameSounds. The sounds are in the root directory of the project under the src. I use JarSplice to export my jars.

Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #4 - Posted 2013-12-16 04:20:57 »

Any help at all? I just need a way to access a file inside a jar either using a URL or a File. Either one works. But it needs to work with an exported jar.

Offline philfrei
« Reply #5 - Posted 2013-12-16 08:33:01 »

URL's are usually the best way to go for resources within a jar. But Finn's example shows the form you were first using is perfectly good. I think normally what you are doing works fine. I'm assuming it plays okay in your IDE.

Is it possible that JarSplice (I've never used it) is set to compress the jar contents? I wonder if that might screw things up, if JarSplice added another layer of compression to your ogg files.

I was looking through the loadMusic chain of command. Finn provides a healthy amount of diagnostics along the way.
1  
private static AudioInputStream getValidAudioStream(URL url) {

I think this is the specific method that is failing for you (not sure). Maybe it would be useful to try putting in some printline's to track your progress through this method and confirm the exact point where the code is failing.

"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 opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #6 - Posted 2013-12-16 11:28:51 »

Ok well if it is failing (let's just say it is), how do I deal with that? I mean there's nothing I can really do about that right?

Edit: I give up. After placing my sound files in a separate folder and trying to load them all I get is a could not get audio resource from input URL. So damn sick of this, I don't think I can turn in my Ludum Dare entry now because of TinySound.

Offline philfrei
« Reply #7 - Posted 2013-12-16 19:31:36 »

Ok well if it is failing (let's just say it is), how do I deal with that? I mean there's nothing I can really do about that right?

I'd try making the jar without compression, just to see if that makes a difference. In Eclipse, one can choose to have the compression or not. I am not familiar with JarSplice or its settings. But if that is an option, the issue is just fuzzy enough for me that I'd want to test it.

I'd also try and step through the program--you can't do that from the .jar, but you can use Printlines to display contents of variables. In general, nailing down the exact situation (as much "state" as there is) for a difficult bug often exposes faulty assumptions.

Another thing I've done when being frustrated with loading resources: I put a copy of the resource in every dam directory where the URL might find it, as a way to see if I have a misunderstanding of the syntax and how it is interpreting the location. I've been confused before about when to use "/" or not at the head of the address, for example. I usually create a file "audio" and have the sounds there, one level below the calling code.

So sorry to hear this is running afoul of the Ludum Dare deadline. Good luck, I hope you get this working in time! I wish I had some better suggestions.

Another idea, if you have time: make a minimum case example, a program that uses TinySound to load and play a single sound and nothing else, and run it as a jar. It should be short enough to fit in a single class that you can post here.

"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 opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #8 - Posted 2013-12-16 22:19:07 »

Thanks for the help but I just decided to write a small OpenAL wrapper and use that. It was quite buggy but it worked out ok... Now I know what I need to learn about for the next Ludum Dare!

Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #9 - Posted 2014-01-05 19:12:50 »

Well, after a couple of weeks I finally figured out what the hell I was doing wrong, and now I feel idiotic about it. When loading my sound files, I was using URLs, which is fine. However, I was trying to load like this:
1  
URL url = GameSound.class.getClassLoader().getResource("res/" + name);

I never noticed that I had put in that in that extra "res/" folder call. When I removed that, everything worked great!

Happy now, but it still sucks that I had to write my own sound class that quite honestly was bad. Stuff barely ever played, and my game really suffered because of it. But I just want to apologize to the author of TinySound if he ever sees this someday. Your library is good!

Pages: [1]
  ignore  |  Print  
 
 

 

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 (63 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (215 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!