I'm using Java sound to play back a number of sound samples with the Clip.start() method.
Given this, what is the best way to control the playback volume?
In particular, I'm very keen that the solution will work reliably across platforms.
Following steps are to be followed to play a clip object. getAudioInputStream(File file). AudioInputStream converts an audio file into stream. Get a clip reference object from AudioSystem. Stream an audio input stream from which audio data will be read into the clip by using open() method of Clip interface.
FloatControl volume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
volume.setValue(gainAmount);
Just replace gainAmount
with a float representing the gain in decibels. Can be positive or negative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With