I'm developing a game in java with some cutesy little 8-bit sfx and I have this incredibly old sound class from 2011 made by notch. It's a good sound class, the only problem is that I can not change the volume of the sounds in it, I have tried multiple times to alter this but I always get really confusing errors and NullPointerExceptions. This is my sound class:

package com.teto.main;
import java.applet.Applet;
import java.applet.AudioClip;
public class Sound {
    public static final Sound levelUp = new Sound("/example.wav");
    private AudioClip clip;
    private Sound(String name) {
        try {
            clip = Applet.newAudioClip(Sound.class.getResource(name));
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    public void play() {
        try {
            new Thread() {
                public void run() {
                    clip.play();
                }
            }.start();
        } catch (Throwable er) {
            er.printStackTrace();
        }
    }
}

As you can see it is using java.applet.AudioClip which I don't think allows you to alter the volume of the sound effects you use with it. So that's why I want to figure out how to replace this with something better, so that I can still type Sound.soundname.play(); but I can also alter the volume.

0

There are 0 best solutions below