private static FloatControl getFirstAvailableControl(Clip clip, FloatControl.Type... types) { for (FloatControl.Type type : types) { if (clip.isControlSupported(type)) { return (FloatControl)clip.getControl(type); } } return null; }
@Nullable public FloatControl getGainControl() { if (gainSupported()) { return (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); } return null; }
public static void setVolume(Clip clip, int level) { Objects.requireNonNull(clip); FloatControl volume = (FloatControl) clip.getControl(FloatControl.Type.VOLUME); if (volume != null) { volume.setValue(level / 100.0); } }
@Nullable public FloatControl getPitchControl() { if (pitchSupported()) { return (FloatControl) clip.getControl(FloatControl.Type.SAMPLE_RATE); } return null; }
public void setVolume(float velocity){ FloatControl volume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); volume.setValue(velocity); }
Clip clipA = AudioSystem.getClip(); Clip clipB = AudioSystem.getClip(); clipA.open(aisA); clipB.open(aisB); for (int i = 0; i < 100; i ++) { FloatControl gainControlA = (FloatControl) clipA.getControl(FloatControl.Type.MASTER_GAIN); gainControlA.setValue(i * -1f); FloatControl gainControlB = (FloatControl) clipB.getControl(FloatControl.Type.MASTER_GAIN); gainControlB.setValue(-100f + i); Thread.sleep(100); }
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("MyClip.wav")); Clip clip = AudioSystem.getClip(); clip.open(audioInputStream); FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.VOLUME); volumeControl.setValue(10.0f); // Increase volume by 10 decibels. clip.start();
public void playSound(String soundLoc) { try { InputStream inputStream = getClass().getResourceAsStream(soundLoc); AudioStream audioStream = new AudioStream(inputStream); AudioPlayer.player.start(audioStream); Clip myclip = AudioSystem.getClip(); myclip.open(audioStream); FloatControl audioControl = (FloatControl) myclip.getControl(FloatControl.Type.MASTER_GAIN); audioControl.setValue(-5.0f); //decrease volume 5 decibels clip.start(); }//end try catch (Exception e) { }//end catch }//end playSound method
void addSampledControls() { try { FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); if (gainControl != null) { this.add(createSlider(gainControl)); } } catch (IllegalArgumentException e) { // If MASTER_GAIN volume control is unsupported, just skip it } try { // FloatControl.Type.BALANCE is probably the correct control to // use here, but it doesn't work for me, so I use PAN instead. FloatControl panControl = (FloatControl) clip.getControl(FloatControl.Type.PAN); if (panControl != null) { this.add(createSlider(panControl)); } } catch (IllegalArgumentException e) { } }
public static void play(Clip clip) { if (Settings.getSettings().isVolumeOn()) { FloatControl control = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); int volume = Settings.getSettings().getVolume(); float range = control.getMinimum(); float result = range * (1 - volume / 100.0f); control.setValue(result); clip.start(); } }
private void play(String wavPath, float db) { if (!dnd && db > -40) { ClassLoader classLoader = getClass().getClassLoader(); try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) { Clip clip = AudioSystem.getClip(); clip.open(stream); if (db != 0.0) { FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(db); } clip.start(); } catch (Exception e) { logger.error("Cannot start playing wav file: ", e); } } } }
String filename="foo.wav"; Clip clip=AudioSystem.getClip(); AudioInputStream inputStream=AudioSystem.getAudioInputStream(new BufferedInputStream(Audio.class.getResourceAsStream(filename))); if(inputStream!=null) { clip.open(inputStream); FloatControl gainControl=(FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(+6.0f); // ? clip.start(); // maybe do not wait? while(clip.getMicrosecondLength()!=clip.getMicrosecondPosition()) Thread.yield(); // wait // or at least don't wait here? Thread.sleep(500); clip.close(); }
public static void main(String[] args) throws Exception { File in = new File("C:\\Users\\Sandra\\Desktop\\music\\rags.wav"); AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(in); Clip play = AudioSystem.getClip(); play.open(audioInputStream); FloatControl volume= (FloatControl)play.getControl(FloatControl.Type.MASTER_GAIN); volume.setValue(1.0f); // Reduce volume by 10 decibels. play.start(); SwingUtilities.invokeLater(new Runnable() { public void run() { // A GUI element to prevent the Clip's daemon Thread // from terminating at the end of the main() JOptionPane.showMessageDialog(null, "Close to exit!"); } }); }
static String randomName = "TreasureQuest"; public static Clip clip = null; public static void playSound(String name) throws Exception{ if (clip != null && clip.isOpen()) clip.close(); AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("music/" + name + ".wav").getAbsoluteFile()); clip = AudioSystem.getClip(); clip.open(audioInputStream); FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(0f); System.out.println(clip.getFrameLength() + " | " + clip.getFramePosition()); clip.start(); }
public static void main(String[] args) throws IOException, UnsupportedAudioFileException, LineUnavailableException { File in = new File("C:\\Users\\Sandra\\Desktop\\music\\rags.wav"); AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(in); Clip play = AudioSystem.getClip(); play.open(audioInputStream); FloatControl volume= (FloatControl) play.getControl(FloatControl.Type.MASTER_GAIN); volume.setValue(1.0f); // Reduce volume by 10 decibels. play.start(); play.drain(); play.close(); }
@Override protected void setVolumeImpl(float volume) { if (impl.isControlSupported(FloatControl.Type.MASTER_GAIN)) { FloatControl volctrl = (FloatControl) impl.getControl(FloatControl.Type.MASTER_GAIN); volctrl.setValue(toGain(volume, volctrl.getMinimum(), volctrl.getMaximum())); } }
@Override protected void setVolumeImpl(float volume) { if (impl.isControlSupported(FloatControl.Type.MASTER_GAIN)) { FloatControl volctrl = (FloatControl) impl.getControl(FloatControl.Type.MASTER_GAIN); volctrl.setValue(toGain(volume, volctrl.getMinimum(), volctrl.getMaximum())); } }
public Reproducao(File som, Integer endereco) throws ErroExecucaoBiblioteca { this.endereco = endereco; try { clip = AudioSystem.getClip(); AudioInputStream stream = criaStream(som); clip.open(stream); stream.close(); if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) { controleDeVolume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); } } catch (Exception excecao) { throw new ErroExecucaoBiblioteca("Não foi possível criar ou abrir uma linha de execução de áudio para " + som.getAbsolutePath()); } }
@Override protected void setVolumeImpl(float volume) { if (impl.isControlSupported(FloatControl.Type.MASTER_GAIN)) { FloatControl volctrl = (FloatControl) impl.getControl(FloatControl.Type.MASTER_GAIN); volctrl.setValue(toGain(volume, volctrl.getMinimum(), volctrl.getMaximum())); } }
@Override protected void setVolumeImpl(float volume) { if (impl.isControlSupported(FloatControl.Type.MASTER_GAIN)) { FloatControl volctrl = (FloatControl) impl.getControl(FloatControl.Type.MASTER_GAIN); volctrl.setValue(toGain(volume, volctrl.getMinimum(), volctrl.getMaximum())); } }