I’m having problems getting sound to work with my java game. (I’m not using the lwjgl b/c I didn’t know about it when I started, but I’m definitely going to use it for my next project :cranky: )
When I run the game in Eclipse, everything works how it’s supposed to, but when I compile into a runnable jar, sound doesn’t play. I also would like help making it loop, but the important part right now is that I get it working
here is the current code I’m using, I create a new musicPlayer class at the beginning then call playMusic when I want to play a song and give it the file location in my project (ex: playMusic(music/Title.au); )
import sun.audio.;
import java.io.;
@SuppressWarnings(“restriction”)
public class musicPlayer{
AudioStream as;
InputStream in;
public musicPlayer(){
}
public void playMusic(String fna){
try {
in = new FileInputStream(new File(this.getClass().getResource(fna).toURI()));
as = new AudioStream(in);
AudioPlayer.player.start(as);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void stopMusic(){
AudioPlayer.player.stop(as);
}
}
I also have a screenshot of my project files so you can see where I have them stored in the src folder:
http://gyazo.com/9ad0ee0537666cbac19060c564a0be7c
the classes are in the default package and the tracks I want to play are in the music folder
Any and all help/ recommendations/ redirection/ ideas are appreciated!