0

I've seen methods to change Clip volume, however, I am using an AudioClip (code below). Is there a good way to change the volume of the clip? Or would I have to instead use a Clip?

    private static AudioClip getcharend() {
    File file = new File("charend.wav");
    AudioClip clip;
    try {
        clip = JApplet.newAudioClip(file.toURL());
        clip.play();
    } catch (Exception e) {
        e.getMessage();
        return null;
    }

    return clip;
}
Dan
  • 13
  • 1
  • 4
  • Applet AudioClip has no support for volume setting. It may be better to use Clip from javax.sound to control the volume. – RealHowTo Mar 29 '17 at 20:28

1 Answers1

0

According to the documentation here

The relative volume level at which the clip is played. Valid range is 0.0 (muted) to 1.0 (full volume). Values are clamped to this range internally so values outside this range will have no additional effect. Volume is controlled by attenuation, so values below 1.0 will reduce the sound level accordingly.

Since the clip object is being returned. you can just use it to set volume. For example calling your Method above in my code

AudioClip audioClip = getcharend(); 
audioClip.setVolume(0.9);
akinmail
  • 638
  • 6
  • 14