List of usage examples for java.applet AudioClip stop
void stop();
From source file:MainClass.java
public static void main(String[] args) { try {//from w w w . j a va2s . c o m URL url = new URL("file:youraudiofile.wav"); AudioClip ac = Applet.newAudioClip(url); ac.play(); System.out.println("Press any key to exit."); System.in.read(); ac.stop(); } catch (Exception e) { System.out.println(e); } }
From source file:de.tor.tribes.ui.windows.ClockFrame.java
public synchronized void playSound(String pSound) { Clip clip = null;//from ww w .ja va 2 s . com AudioClip ac = null; try { if (org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS) { clip = AudioSystem.getClip(); BufferedInputStream bin = new BufferedInputStream( ClockFrame.class.getResourceAsStream("/res/" + pSound + ".wav")); AudioInputStream inputStream = AudioSystem.getAudioInputStream(bin); clip.open(inputStream); clip.start(); } else { ac = Applet.newAudioClip(ClockFrame.class.getResource("/res/" + pSound + ".wav")); ac.play(); } } catch (Exception e) { logger.error("Failed to play sound", e); } try { Thread.sleep(2500); } catch (Exception ignored) { } try { if (clip != null) { clip.stop(); clip.flush(); clip = null; } if (ac != null) { ac.stop(); ac = null; } } catch (Exception ignored) { } }