Search code examples
javaaudiovolume

How can I change the volume of an audio file in java


Here is my code:

URL url = this.getClass().getClassLoader().getResource(file);
    AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
    Clip clip = AudioSystem.getClip();
    clip.open(audioIn);

    clip.loop(Clip.LOOP_CONTINUOUSLY);

What can I add to reduce the volume


Solution

  • If you're using the Java Sound API, you can set the volume with the MASTER_GAIN control.

    Check this stackoverflow post: LINK