TinySound exporting issues

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:

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:

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?

So now I’ve tried this:


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.

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

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:


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.

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.

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.

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.

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.

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.

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!

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:


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!