The easiest way to do this is to use jlayer via mp3spi which basically means you use jlayer via JavaSound. You can then set gain on the line as you would in JavaSound.
Firstly, you will need to add the following to your classpath:
- jl1.0.1.jar
- mp3spi1.9.5.jar
- tritonus_share.jar
...all of which are in the distribution for mp3spi (linked above).
Secondly, you will need to decode the AudioInputStream prior to playback.
AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
AudioFormat baseFormat = audioStream.getFormat();
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
AudioInputStream audioStream2 = AudioSystem.getAudioInputStream(decodedFormat, audioStream);
Then you play the decoded stream:
Clip clip = AudioSystem.getClip();
clip.open(audioStream2);
and JavaSound API controls are available:
FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(-30.0f);
NOTE: Don't forget to close your resources, I've just shown the key points for this issue - familiarity with JavaSound is expected, read here.