This is kind of an extension from a previous post that I did. The following code I got from KevinWorkman and it deals with loading a wav file as a resource. I took Kevin's code and created a stand alone program to see if it works. I can get it to compile and run without errors but no sound plays. I'm using Eclipse IDE.
I've imported the wav file into the src directory which contains the class that calls the resource. I've also imported it into the root directory of the project itself. I've used a forward slash at the beginning of the file name. I also tried to just load it as a File instead of using getClass().getResource("boxing_bell.wav"); I can't get it to play.
I'm at a complete loss.
Here's the code:
public class playClip { private Clip music; private void startSong(){ try{ System.out.println("Starting...\n"); AudioInputStream stream = AudioSystem.getAudioInputStream( getClass().getResource("boxing_bell.wav")); // AudioInputStream stream = AudioSystem.getAudioInputStream(new File("boxing_bell.wav")); music = AudioSystem.getClip(); music.open(stream); music.start(); System.out.println("Done...\n"); } catch(Exception e){ e.printStackTrace(); music = null; } } public static void main(String args[]) { playClip play = new playClip(); play.startSong(); } }
I also tried making a resource directory within the src directory and including that in the build path.
Any ideas of what I'm doing wrong? I think it has more to do with Eclipse than the code. The reason I say this is I found a book on Safari Online that is almost identical to the code above.
Can you say "Clueless!"
Thanks
Curt