How do I play sound in an application?
Created Jan 29, 2000
John Zukowski
Besides using File to locate the audio file in the application, you can also use the getResource() or getSystemResource() methods of ClassLoader.
Starting with the 1.2 release of Java, you can use the newAudioClip() method of Applet to get an AudioClip to play in an application.
File file = new File("bark.wav");
AudioClip clip = Applet.newAudioClip(file.toURL());
clip.play();
In prior versions of the Java libraries, you had to rely on the non-standard sun.audio package and play them with the AudioPlayer class found in that package.