private static void init() { try { // 44,100 samples per second, 16-bit audio, mono, signed PCM, little Endian AudioFormat format = new AudioFormat((float) SAMPLE_RATE, BITS_PER_SAMPLE, 1, true, false); DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); line = (SourceDataLine) AudioSystem.getLine(info); line.open(format, SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE); // the internal buffer is a fraction of the actual buffer size, this choice is arbitrary // it gets divided because we can't expect the buffered data to line up exactly with when // the sound card decides to push out its samples. buffer = new byte[SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE/3]; } catch (LineUnavailableException e) { System.out.println(e.getMessage()); } // no sound gets made before this call line.start(); }
logger.severe("microphone unavailable " + e.getMessage());
audioLine.open(finalFormat, audioBufferSize); } catch (LineUnavailableException e) { logger.severe("Can't open microphone " + e.getMessage()); return false;
/** * Open the current line */ public void openLine(){ try { this.line.open(format); } catch (LineUnavailableException e) { System.out.println("Unable to open line:" + e.getMessage()); } }
/** * Get a connection to the speaker, if available. * @param audioFormat The java audio format that we will use. * @return A new audio format, or null if we cannot create one. */ public static AudioFrame make(final AudioFormat audioFormat) { try { return new AudioFrame(audioFormat); } catch (LineUnavailableException e) { log.error("Could not get audio data line: {}", e.getMessage()); return null; } }
/** * Gets a data line for the specified mixer * @param mix * @return */ public Line getDataLineForMixer(){ TargetDataLine line = null; try { line = (TargetDataLine) this.mixer.getLine(getDataLineInfo()); } catch (LineUnavailableException e) { System.out.println("Error getting mix line:" + e.getMessage()); } return line; }
/** * @param name The name of the sound file (no extension) */ private static void play(String name) { Preconditions.checkState(allSounds.containsKey(name), "'" + name + "' must be present (did you initialise?)"); byte[] sound = allSounds.get(name); try { final Clip clip = AudioSystem.getClip(); clip.addLineListener(new LineListener() { @Override public void update(LineEvent event) { if (event.getType() == LineEvent.Type.STOP) clip.close(); } }); clip.open(AudioSystem.getAudioInputStream(new ByteArrayInputStream(sound))); clip.start(); } catch (UnsupportedAudioFileException e) { throw new IllegalStateException(e.getMessage()); } catch (IOException e) { throw new IllegalStateException(e.getMessage()); } catch (LineUnavailableException e) { throw new IllegalStateException(e.getMessage()); } }
private static SourceDataLine getLine(AudioFormat audioFormat) { SourceDataLine res = null; DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat); try { res = (SourceDataLine) AudioSystem.getLine(info); res.open(audioFormat); } catch (javax.sound.sampled.LineUnavailableException ex) { System.err.println(ex.getMessage()); res = null; } return res; }
private void loadDataLine() { final DataLine.Info dataInfo = new DataLine.Info(SourceDataLine.class, this.sound.getFormat()); try { this.dataLine = (SourceDataLine) AudioSystem.getLine(dataInfo); if (!dataLine.isOpen()) { this.dataLine.open(); } } catch (final LineUnavailableException e) { log.log(Level.SEVERE, e.getMessage(), e); } }
private static void init() { try { // 44,100 samples per second, 16-bit audio, mono, signed PCM, little Endian AudioFormat format = new AudioFormat((float) SAMPLE_RATE, BITS_PER_SAMPLE, 1, true, false); DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); line = (SourceDataLine) AudioSystem.getLine(info); line.open(format, SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE); // the internal buffer is a fraction of the actual buffer size, this choice is arbitrary // it gets divided because we can't expect the buffered data to line up exactly with when // the sound card decides to push out its samples. buffer = new byte[SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE / 3]; } catch (LineUnavailableException e) { System.out.println(e.getMessage()); System.exit(1); } // no sound gets made before this call line.start(); }
private static void init() { try { // 44,100 samples per second, 16-bit audio, mono, signed PCM, little Endian AudioFormat format = new AudioFormat((float) SAMPLE_RATE, BITS_PER_SAMPLE, 1, true, false); DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); line = (SourceDataLine) AudioSystem.getLine(info); line.open(format, SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE); // the internal buffer is a fraction of the actual buffer size, this choice is arbitrary // it gets divided because we can't expect the buffered data to line up exactly with when // the sound card decides to push out its samples. buffer = new byte[SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE/3]; } catch (LineUnavailableException e) { System.out.println(e.getMessage()); } // no sound gets made before this call line.start(); }
System.err.println(ex.getMessage()); return; System.err.println(ex.getMessage()); return;
logger.severe("microphone unavailable " + e.getMessage());
audioLine.open(finalFormat, audioBufferSize); } catch (LineUnavailableException e) { logger.severe("Can't open microphone " + e.getMessage()); return false;
logger.error(uafe); } catch (LineUnavailableException lue) { JOptionPane.showMessageDialog(null, lue.getMessage()); logger.error(lue); } catch (IOException ioe) {
} catch (LineUnavailableException e) { e.printStackTrace(); throw new InternalError(e.getMessage());
public synchronized void play() { stop(); if (clip == null) { try { clip = createClip(); clip.open(getAudioFormat(), samples.clone(), 0, samples.length); if (clip.isControlSupported(FloatControl.Type.PAN)) { FloatControl control = (FloatControl) clip.getControl(FloatControl.Type.PAN); control.setValue(pan); } if (clip.isControlSupported(FloatControl.Type.VOLUME)) { FloatControl control = (FloatControl) clip.getControl(FloatControl.Type.VOLUME); control.setValue(volume / 64f); } clip.start(); } catch (LineUnavailableException e) { e.printStackTrace(); throw new InternalError(e.getMessage()); } } }
m_javaSoundLine.open(m_javaSoundAudioFormat, bufferSizeBytes); } catch (LineUnavailableException e) { throw new RuntimeException(e.getMessage(), e);
} catch (LineUnavailableException e) { e.printStackTrace(); throw new InternalError(e.getMessage());