How can I play an audio with the animation on the same time.
private final AudioClip soundRed = new AudioClip(getClass().getResource("resources/soundRed.mp3").toExternalForm());
private void computerButtonBlink() {
buttonTransparent(true);
SequentialTransition s = new SequentialTransition();
s.setDelay(Duration.seconds(1.2));
s.setCycleCount(1);
s.setAutoReverse(false);
for (int i = 0; i < gameLogic.getComputerArray().size(); i++) {
switch (gameLogic.getComputerArray().get(i)) {
case 0:
FadeTransition redft = new FadeTransition(Duration.millis(400), bRed);
redft.setAutoReverse(true);
redft.setFromValue(1.0);
redft.setToValue(0.1);
redft.setCycleCount(2);
soundRed.play(); // Sound will start before Animation... Too early...
s.getChildren().add(redft);
break;
default:
break;
}
s.play();
}
And this will play the audio too late:
redft.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
soundRed.play();
}
});
Adding a delay on the audio is not what I'm looking for.