Search in sources :

Example 1 with LineUnavailableException

use of javax.sound.sampled.LineUnavailableException in project screenbird by adamhub.

the class RecorderPanel method startCountdown.

/**
     * Initiates countdown and prepares for screen capture. 
     */
private void startCountdown() {
    final Countdown[] countdown = new Countdown[1];
    countdownSec = 6;
    countdownTimer = new Timer(500, new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            countdownSec--;
            log("Counting: " + countdownSec);
            switch(countdownSec) {
                case 0:
                    countdownTimer.stop();
                    jLabel5.setText("Recording");
                    btnRecordNonRec.setText("Stop");
                    btnRecordRec.setText("Stop");
                    btnPlayPauseBackup.setText("");
                    btnPlayPauseBackup.setIcon(pauseIcon);
                    btnFinalizeBackup.setEnabled(true);
                    // Destroy the countdown window.
                    countdown[0].destroy();
                    try {
                        Thread.sleep(500);
                    } catch (Exception ee) {
                    }
                    startRecordState();
                    break;
                case 1:
                case 2:
                case 3:
                case 4:
                    btnPlayPauseBackup.setText(String.valueOf(countdownSec));
                    countdown[0].destroy();
                    countdown[0] = new Countdown(false, recorder);
                    countdown[0].setCount(countdownSec);
                    countdown[0].setVisible(true);
                    try {
                        SoundUtil.tone(880, 500, 0.15);
                    } catch (LineUnavailableException ee) {
                    }
                    break;
                case 5:
                    btnPlayPauseBackup.setText(String.valueOf(countdownSec));
                    // Hide drop box
                    if (captureBox != null) {
                        captureBox.setDragBoxVisible(false);
                    }
                    countdown[0] = new Countdown(false, recorder);
                    countdown[0].setCount(5);
                    countdown[0].setVisible(true);
                    try {
                        SoundUtil.tone(880, 500, 0.15);
                    } catch (LineUnavailableException ee) {
                    }
                    break;
            }
        }
    });
    countdownTimer.start();
}
Also used : Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) LineUnavailableException(javax.sound.sampled.LineUnavailableException) Countdown(com.bixly.pastevid.screencap.components.capturebox.Countdown) MissingResourceException(java.util.MissingResourceException) FileNotFoundException(java.io.FileNotFoundException) LineUnavailableException(javax.sound.sampled.LineUnavailableException) IOException(java.io.IOException)

Example 2 with LineUnavailableException

use of javax.sound.sampled.LineUnavailableException in project jdk8u_jdk by JetBrains.

the class DataLine_ArrayIndexOutOfBounds method testSDL.

static void testSDL(Mixer mixer, Scenario scenario) {
    log("  Testing SDL (scenario: " + scenario + ")...");
    Line.Info linfo = new Line.Info(SourceDataLine.class);
    SourceDataLine line = null;
    try {
        line = (SourceDataLine) mixer.getLine(linfo);
        log("    got line: " + line);
        log("    open...");
        line.open();
    } catch (IllegalArgumentException ex) {
        log("    unsupported (IllegalArgumentException)");
        return;
    } catch (LineUnavailableException ex) {
        log("    unavailable: " + ex);
        return;
    }
    total++;
    log("    start...");
    line.start();
    AsyncLineStopper lineStopper = new AsyncLineStopper(line, STOPPER_DELAY);
    int offset = scenario.getBufferOffset(line);
    int len = scenario.getBufferLength(line);
    // ensure len represents integral number of frames
    len -= len % line.getFormat().getFrameSize();
    log("    write...");
    lineStopper.schedule();
    try {
        line.write(buffer, offset, len);
        log("    ERROR: didn't get ArrayIndexOutOfBoundsException");
        failed++;
    } catch (ArrayIndexOutOfBoundsException ex) {
        log("    OK: got ArrayIndexOutOfBoundsException: " + ex);
    }
    lineStopper.force();
}
Also used : TargetDataLine(javax.sound.sampled.TargetDataLine) Line(javax.sound.sampled.Line) DataLine(javax.sound.sampled.DataLine) SourceDataLine(javax.sound.sampled.SourceDataLine) LineUnavailableException(javax.sound.sampled.LineUnavailableException) SourceDataLine(javax.sound.sampled.SourceDataLine)

Example 3 with LineUnavailableException

use of javax.sound.sampled.LineUnavailableException in project JMRI by JMRI.

the class Sound method playSoundBuffer.

/**
     * Play a sound from a buffer
     *
     * @param wavData data to play
     */
public static void playSoundBuffer(byte[] wavData) {
    // get characteristics from buffer
    float sampleRate = 11200.0f;
    int sampleSizeInBits = 8;
    int channels = 1;
    boolean signed = (sampleSizeInBits > 8);
    boolean bigEndian = true;
    AudioFormat format = new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
    SourceDataLine line;
    // format is an AudioFormat object
    DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
    if (!AudioSystem.isLineSupported(info)) {
        // Handle the error.
        log.warn("line not supported: " + info);
        return;
    }
    // Obtain and open the line.
    try {
        line = (SourceDataLine) AudioSystem.getLine(info);
        line.open(format);
    } catch (LineUnavailableException ex) {
        // Handle the error.
        log.error("error opening line: " + ex);
        return;
    }
    line.start();
    // write(byte[] b, int off, int len) 
    line.write(wavData, 0, wavData.length);
}
Also used : DataLine(javax.sound.sampled.DataLine) SourceDataLine(javax.sound.sampled.SourceDataLine) LineUnavailableException(javax.sound.sampled.LineUnavailableException) SourceDataLine(javax.sound.sampled.SourceDataLine) AudioFormat(javax.sound.sampled.AudioFormat)

Example 4 with LineUnavailableException

use of javax.sound.sampled.LineUnavailableException in project JMRI by JMRI.

the class JavaSoundAudioSource method bindAudioBuffer.

@SuppressWarnings("SleepWhileInLoop")
@Override
boolean bindAudioBuffer(AudioBuffer audioBuffer) {
    // First check we've been initialised
    if (!initialised) {
        return false;
    }
    // Wait for AudioBuffer to be loaded, or 20 seconds
    long startTime = System.currentTimeMillis();
    while (audioBuffer.getState() != AudioBuffer.STATE_LOADED && System.currentTimeMillis() - startTime < 20000) {
        try {
            Thread.sleep(50);
        } catch (InterruptedException ex) {
        }
    }
    if (audioBuffer instanceof JavaSoundAudioBuffer && audioBuffer.getState() == AudioBuffer.STATE_LOADED) {
        // Cast to JavaSoundAudioBuffer to enable easier access to specific methods
        JavaSoundAudioBuffer buffer = (JavaSoundAudioBuffer) audioBuffer;
        // Get a JavaSound DataLine and Clip
        DataLine.Info lineInfo;
        lineInfo = new DataLine.Info(Clip.class, buffer.getAudioFormat());
        Clip newClip;
        try {
            newClip = (Clip) mixer.getLine(lineInfo);
        } catch (LineUnavailableException ex) {
            log.warn("Error binding JavaSoundSource (" + this.getSystemName() + ") to AudioBuffer (" + this.getAssignedBufferName() + ") " + ex);
            return false;
        }
        this.clip = newClip;
        try {
            clip.open(buffer.getAudioFormat(), buffer.getDataStorageBuffer(), 0, buffer.getDataStorageBuffer().length);
        } catch (LineUnavailableException ex) {
            log.warn("Error binding JavaSoundSource (" + this.getSystemName() + ") to AudioBuffer (" + this.getAssignedBufferName() + ")" + ex);
        }
        if (log.isDebugEnabled()) {
            log.debug("Bind JavaSoundAudioSource (" + this.getSystemName() + ") to JavaSoundAudioBuffer (" + audioBuffer.getSystemName() + ")");
        }
        return true;
    } else {
        log.warn("AudioBuffer not loaded error when binding JavaSoundSource (" + this.getSystemName() + ") to AudioBuffer (" + this.getAssignedBufferName() + ")");
        return false;
    }
}
Also used : Clip(javax.sound.sampled.Clip) DataLine(javax.sound.sampled.DataLine) LineUnavailableException(javax.sound.sampled.LineUnavailableException)

Example 5 with LineUnavailableException

use of javax.sound.sampled.LineUnavailableException in project jdk8u_jdk by JetBrains.

the class SoftMixingMixer method openStream.

public AudioInputStream openStream(AudioFormat targetFormat) throws LineUnavailableException {
    if (isOpen())
        throw new LineUnavailableException("Mixer is already open");
    synchronized (control_mutex) {
        open = true;
        implicitOpen = false;
        if (targetFormat != null)
            format = targetFormat;
        mainmixer = new SoftMixingMainMixer(this);
        sendEvent(new LineEvent(this, LineEvent.Type.OPEN, AudioSystem.NOT_SPECIFIED));
        return mainmixer.getInputStream();
    }
}
Also used : LineEvent(javax.sound.sampled.LineEvent) LineUnavailableException(javax.sound.sampled.LineUnavailableException)

Aggregations

LineUnavailableException (javax.sound.sampled.LineUnavailableException)16 DataLine (javax.sound.sampled.DataLine)11 SourceDataLine (javax.sound.sampled.SourceDataLine)7 IOException (java.io.IOException)6 AudioInputStream (javax.sound.sampled.AudioInputStream)6 AudioFormat (javax.sound.sampled.AudioFormat)5 Clip (javax.sound.sampled.Clip)3 Mixer (javax.sound.sampled.Mixer)3 TargetDataLine (javax.sound.sampled.TargetDataLine)3 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)3 FileNotFoundException (java.io.FileNotFoundException)2 URL (java.net.URL)2 Line (javax.sound.sampled.Line)2 Countdown (com.bixly.pastevid.screencap.components.capturebox.Countdown)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 FileInputStream (java.io.FileInputStream)1 MissingResourceException (java.util.MissingResourceException)1 MidiUnavailableException (javax.sound.midi.MidiUnavailableException)1 LineEvent (javax.sound.sampled.LineEvent)1