List of usage examples for javax.sound.sampled AudioSystem getAudioInputStream
public static AudioInputStream getAudioInputStream(final File file) throws UnsupportedAudioFileException, IOException
From source file:la2launcher.MainFrame.java
public static synchronized void playSound() { new Thread(new Runnable() { // The wrapper thread is unnecessary, unless it blocks on the // Clip finishing; see comments. public void run() { try { Clip clip = AudioSystem.getClip(); AudioInputStream inputStream = AudioSystem.getAudioInputStream( new BufferedInputStream(this.getClass().getResourceAsStream("alert.vaw"))); clip.open(inputStream);/*from w w w .j av a 2 s . c om*/ //clip.start(); } catch (Exception e) { System.err.println(e.getMessage()); } } }).start(); }
From source file:marytts.tools.redstart.AdminWindow.java
private void jButton_DisplayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_DisplayActionPerformed Prompt selectedPrompt = promptArray[getCurrentRow()]; try {/* w w w.jav a2 s .c om*/ File f = selectedPrompt.getRecording().getFile(); AudioInputStream audio = AudioSystem.getAudioInputStream(f); if (audio.getFormat().getChannels() > 1) { audio = new MonoAudioInputStream(audio, optionsDialog.getInputMode()); } MultiDisplay d = new MultiDisplay(audio, selectedPrompt.getBasename(), false); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.yccheok.jstock.gui.Utils.java
public static void playAlertSound() { new Thread(new Runnable() { @Override// ww w .j a v a2 s . c om 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(); }
From source file:GUI.AllForDealFrame.java
private void btnSonOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSonOnActionPerformed // TODO add your handling code here: Mixer.Info[] mixInfo = AudioSystem.getMixerInfo(); mixer = AudioSystem.getMixer(mixInfo[0]); DataLine.Info dataLine = new DataLine.Info(Clip.class, null); try {// w ww . j a va 2 s . c om clip = (Clip) mixer.getLine(dataLine); } catch (LineUnavailableException ex) { ex.printStackTrace(); } try { URL soundURL = this.getClass().getResource("/images/The_Eagles-Hotel_California_acoustic_live_www.wav"); AudioInputStream audioImput = AudioSystem.getAudioInputStream(soundURL); clip.open(audioImput); } catch (LineUnavailableException ex) { ex.printStackTrace(); } catch (UnsupportedAudioFileException exp) { exp.printStackTrace(); } catch (IOException io) { io.printStackTrace(); } clip.start(); }