I made a little game, where always background music should be played in a loop. I took this code but that does not work. First it plays as expected, then it begins to overloop and it is impossible to listen to. What did I make wrong?
final Task task = new Task() {
@Override
protected Object call() throws Exception {
int s = INDEFINITE;
AudioClip audio = new AudioClip(getClass().getResource("aquarium.mp3").toExternalForm());
audio.setVolume(0.5f);
audio.setCycleCount(s);
audio.play();
return null;
}
};
Thread thread = new Thread(task);
thread.start();
The problem was my mp3-File. I took a wav-File, and everything worked.
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