I've got a problem regarding audio.
I am coding in Java using Netbeans, and I want to export my project so that it doesn't require Netbeans to run, so I decided to create a JAR File. I put all the images, and audio files (aiff) for my program in the src folder so that they could be accessible from outside the coding console.
I have declared my InputStream and AudioStream as global variables, and I am using them within a try catch block, where the code is run when a button is clicked.
AudioPlayer.player.stop(audios);
try{
in = new FileInputStream (new File("src/glory.aiff"));
System.out.println("Button Clicked");
audios = new AudioStream (in);
AudioPlayer.player.start(audios);
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
This code perfectly fine when I run the program on Netbeans, however when I create a JAR file, the audio doesn't play, and an error pops up saying that the file cannot be found. I've tried this on my computer, and other computers, and the same problem occurs.
What I find strange, is that the pictures I mentioned earlier are in the same SRC folder, and they display correctly. I have linked these pictures through the use of icons, and Netbeans auto-generates code for that.
jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMG_2138.JPG")));
I have done research of my own, however other people who have this problem don't seem to be using the same AudioStream as myself and I don't know how to adapt it to solve my problem! I've also tried changing the file path of the audio, but whenever it has worked in Netbeans, it has not worked in my JAR file.
Would anyone please be able to tell me how I could fix this problem?
Thanks,
Rohan