I have an FX Application where, from the beginning, it starts playing music, which works. Now I want that when I open a method to play another sound on top of it.
I coded the second sound like the first but it isn't working. I tried making a new Thread
but no change.
The new sound is actually playing somehow. Sometimes it doesn't play at all. Sometimes entirely and sometimes for just one sec.
Method with new sound
public void showFight(int fighterLeft, int fighterRight) throws InterruptedException {
//Some code
new Thread(() -> {
music2();
}).start();
new Thread(() -> {
try {
Thread.sleep(3000L);
} catch (InterruptedException e) {
}
Platform.runLater(() -> {
//FadeIn();
FightPane.setVisible(false);
});
}).start();
}
public static void music2() {
Media hit2 = new Media(JavaFXApplicationStratego.class.getResource("/Sounds/fight.mp3").toString());
MediaPlayer mediaPlayer2 = new MediaPlayer(hit2);
mediaPlayer2.play();
}
First Sound
public static void music() {
String bip = "/stopen.mp3";
Media hit = new Media(JavaFXApplicationStratego.class.getResource("/Sounds/stopen.mp3").toString());
MediaPlayer mediaPlayer = new MediaPlayer(hit);
mediaPlayer.play();
}