0

I currently have an LWJGL game with background music. When I run my game in Eclipse everything seems fine. The music also works when I export it as a runnable jar. However, when I put my game on a web server and a client downloads and runs it, the music doesn't play. I initially had the following:

try{
    File file = new File ("/Users/me/Documents/workspace/LWJGL-T/src/file.mp3");
    FileInputStream fileStream = new FileInputStream (file);
    BufferedInputStream bufferStream = new BufferedInputStream (fileStream);
    Player player = new Player (bufferStream);
    player.play();
}
catch (Exception e){
   System.err.println (e.toString());
}

After some research, I found out that FileInputStream shouldn't be used with mp3 files so I implemented the following, which didn't work at all.

    InputStream fileStream = this.getClass().getResourceAsStream("/Users/me/Documents/workspace/LWJGL-T/src/file.mp3");

Any help would be appreciated; thank you!

  • Why do you think the user would have `/Users/me/Documents/workspace/LWJGL-T/src/file.mp3` on the PC? If you want the make the file available at runtime to the user, you should embed the file within the Jar and then you can make use of `getResourceAsStream` – MadProgrammer Jan 11 '17 at 02:12
  • Will take a chance... It looks like the file is on your local box. – Mordechai Jan 11 '17 at 02:12

1 Answers1

0

As stated in the comments below your original post, the file you're trying to access is only stored on your computer. You'll have to include the file in your jar (see this post for setting that up) and after that, the line below should work:

InputStream fileStream = this.getClass().getResourceAsStream("/file.mp3");
Community
  • 1
  • 1
Qw2
  • 1
  • 1