Java-GNOME provides the ability to play sounds through the Sound class. This class is so simple to use that an example will be the best demonstration.
Example 7-3. Sound.java - Sound
import org.gnu.gnome.Program; import org.gnu.gnome.Sound; public class SoundTest { public SoundTest() { Sound.play("startup.wav"); Sound.shutdown(); } public static void main(String[] args) { Program.initGnome("Sound Example", "1.0", args); SoundTest sound = new SoundTest(); } }
As you might guess, this example plays a file called "startup.wav". Before you exit the application you should place a call to Sound.shutdown() to free up the resources taken by the sound daemon.