The problem I have is that the decibals of the audiofile only changes from the initial value of programVolume (the variable) but I have a JSlider that alters the the value of the variable;however, it does not alter the decibals of the file. What do I add/change to make sure the decibal changes based off the values set to the variable from the JSlider.
File fileSong = new File (filePath);
AudioInputStream input = AudioSystem.getAudioInputStream(fileSong);
clip = AudioSystem.getClip();
clip.open(input);
FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(programVolume);
clip.start();
EDIT:
I have added the following code:
File fileSong = new File (filePath);
AudioInputStream input = AudioSystem.getAudioInputStream(fileSong);
clip = AudioSystem.getClip();
clip.open(input);
FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
float range = gainControl.getMaximum() - gainControl.getMinimum();
float gain = (range * programVolume) + gainControl.getMinimum();
gainControl.setValue(gain);
For my JSlider (which is in the method ChangeEvent e)
programVolume = (float)volume.getValue() / 100;
I am still facing the same problem. The new values recieved from the JSlider do not change the volume. Only the initial value of programVolume alters the sound.