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();
}
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();
}
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);
}
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;
}
}
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();
}
}
Aggregations