I have this very rough draft of a class to manage an AudioCue instance. The “setSpeed” method is called in another method every game frame and the values are managed in said method, too.
Here’s the code for the class
package ...
import ...
public class Player {
private URL url;
private AudioCue cue;
private int handle;
public Player(String audioPath) throws MalformedURLException, IOException, UnsupportedAudioFileException {
this.url = new URL(audioPath);
cue = AudioCue.makeStereoCue(url, 1);
}
public void start() throws UnsupportedAudioFileException, IOException, LineUnavailableException {
AudioInputStream ais = AudioSystem.getAudioInputStream(url);
int frameLength = (int) ais.getFrameLength();
cue.open(frameLength);
handle = cue.play();
}
public void setSpeed(float speed) {
System.out.println("Previous speed: " + cue.getSpeed(handle));
System.out.println("Changing speed: " + speed);
cue.setSpeed(handle, speed);
}
public void setVolume(float volume) {
cue.setVolume(handle, volume);
}
public boolean getIsActive() {
return cue.getIsActive(handle);
}
public void stop() {
cue.stop(handle);
cue.close();
}
}
But when I call setSpeed() the speed of the AudioCue instance never changes.
I’m fairly sure I’m doing something wrong but I don’t really know where the error could be. Any help would be great. Thanks in advance.