Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX background thread task should play music in a loop as background thread

Tags:

javafx

audio

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();
like image 244
fhs14647 Avatar asked Aug 03 '15 10:08

fhs14647


1 Answers

The problem was my mp3-File. I took a wav-File, and everything worked.

like image 55
fhs14647 Avatar answered Nov 03 '22 17:11

fhs14647