0

I know this question has been asked before, but I couldn't actually understand the solution to the problem, that's why I'm posting my code specifically!

When I run the program from netbeans the music is just fine. However, when I run it from the jar file, the program is executed smoothly, but without music.

I used this code to play music: http://www.anyexample.com/programming/java/java_play_wav_sound_file.xml

And I call the function like this in GUI class:

musicPlayer = new AePlayWave("src/songs/Full_Despicable_Me_Theme_Song_-_Pharrell_Williams.wav");
        musicPlayer.start();

(as you can see I have a package called "songs", which contains the song)

Hope you can help!

jmj
  • 237,923
  • 42
  • 401
  • 438
syfantid
  • 366
  • 5
  • 20
  • have a look at that: http://stackoverflow.com/questions/3861989/preferred-way-of-loading-resources-in-java – Simiil Jan 25 '14 at 22:28
  • Don't include "src" in the path, it won't exist once the program is built. You may need to use Class#getResource or Class#getRescourceAsStream depending of the API you are using – MadProgrammer Jan 25 '14 at 22:40

1 Answers1

0

Constructor of AePlayWave takes file path as parameter, when you have your music file inside jar file, it is no longer a File

You can read that file and write it out to some temp directory on the bootstrap of your program and read it as File from that location

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438