import java.io.*;
import javax.sound.sampled.*;

public class SoundDemo {

    public static void main(String[] args) throws Exception {
        // Using first argument for sound file name
        String soundFileName = args[0];
        
        // Get an input stream for the sound file
        ClassLoader cl = SoundDemo.class.getClassLoader();
        InputStream in = cl.getResourceAsStream(soundFileName);

        // Not all encodings will work (mp3 is right out, for example)

        // An uncompressed wav file should be fine, but bear in mind
        // that not all wav files are in uncompressed format.

        // You'll need to convert the file if your sound effects are
        // in an unsupported format.

        // Convert input stream into audio input stream
        AudioInputStream audioIn = AudioSystem.getAudioInputStream(in);

        // Clip is what will actually play the file
        Clip clip = AudioSystem.getClip();
        clip.open(audioIn);

        // Before starting playback, you may want to configure the
        // start position, looping points, etc.
        //clip.setFramePosition(0);

        // When all is ready, start playback.
        clip.start();

        // Instead of start, can use loop to play repeatedly
        //clip.loop(20);

        // You can stop playback with the stop method.
    }
}
