83b /* Plays sound clips */ import javax.sound.sampled.*; import java.io.*; public class SoundClip implements Runnable { private static boolean isPlaying = false; private String fileName; public SoundClip(String fileName) { isPlaying = true; this.fileName = fileName; Thread thread = new Thread(this); thread.start(); } public void run() { File file = new File(fileName); try { AudioInputStream stream = AudioSystem.getAudioInputStream(file); AudioFormat format = stream.getFormat(); /** * we can't yet open the device for ALAW/ULAW playback, * convert ALAW/ULAW to PCM */ if ((format.getEncoding() == AudioFormat.Encoding.ULAW) || (format.getEncoding() == AudioFormat.Encoding.ALAW)) { AudioFormat tmp = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(), format.getSampleSizeInBits() * 2, format.getChannels(), format.getFrameSize() * 2, format.getFrameRate(), true); stream = AudioSystem.getAudioInputStream(tmp, stream); format = tmp; } DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat(), ((int)stream.getFrameLength() * format.getFrameSize())); Clip clip = (Clip)AudioSystem.getLine(info); clip.open(stream); // Adjust the volume on the output line. if(clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) { FloatControl volume = (FloatControl)clip.getControl( FloatControl.Type.MASTER_GAIN); volume.setValue(5.0F); } clip.start(); while (clip.isActive()) { try {Thread.sleep(99);} catch (Exception e) {break;} } Thread.sleep(1000); clip.stop(); clip.close(); } catch (Exception e) { e.printStackTrace(); } isPlaying = false; } public static void main(String [] args) { for (int i = 0; i < args.length; i++) { new SoundClip(args[i]); while (isPlaying) try {Thread.sleep(99);} catch (Exception e) {} } System.exit(0); } } . 0