List of usage examples for javax.sound.sampled AudioSystem getClip
public static Clip getClip() throws LineUnavailableException
From source file:org.yccheok.jstock.gui.Utils.java
public static void playAlertSound() { new Thread(new Runnable() { @Override/*from www . j av a 2 s . c o m*/ public void run() { try { Clip clip = AudioSystem.getClip(); clip.addLineListener(new LineListener() { @Override public void update(LineEvent event) { if (event.getType() == LineEvent.Type.STOP) { event.getLine().close(); } } }); final InputStream audioSrc = Utils.class.getResourceAsStream("/assets/sounds/doorbell.wav"); // http://stackoverflow.com/questions/5529754/java-io-ioexception-mark-reset-not-supported // Add buffer for mark/reset support. final InputStream bufferedIn = new BufferedInputStream(audioSrc); AudioInputStream inputStream = AudioSystem.getAudioInputStream(bufferedIn); clip.open(inputStream); clip.start(); } catch (Exception e) { log.error(null, e); } } }).start(); }