Example usage for javax.sound.sampled LineUnavailableException printStackTrace

List of usage examples for javax.sound.sampled LineUnavailableException printStackTrace

Introduction

In this page you can find the example usage for javax.sound.sampled LineUnavailableException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Filter3dTest.java

/**
 * Plays a stream. This method blocks (doesn't return) until the sound is
 * finished playing./* w  w  w.  j  ava2  s .  c  o m*/
 */
public void play(InputStream source) {

    // use a short, 100ms (1/10th sec) buffer for real-time
    // change to the sound stream
    int bufferSize = format.getFrameSize() * Math.round(format.getSampleRate() / 10);
    byte[] buffer = new byte[bufferSize];

    // create a line to play to
    SourceDataLine line;
    try {
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
        line = (SourceDataLine) AudioSystem.getLine(info);
        line.open(format, bufferSize);
    } catch (LineUnavailableException ex) {
        ex.printStackTrace();
        return;
    }

    // start the line
    line.start();

    // copy data to the line
    try {
        int numBytesRead = 0;
        while (numBytesRead != -1) {
            numBytesRead = source.read(buffer, 0, buffer.length);
            if (numBytesRead != -1) {
                line.write(buffer, 0, numBytesRead);
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    // wait until all data is played, then close the line
    line.drain();
    line.close();

}

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 {/*from w w w . ja v a  2s . 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();
}