I'm making a sound player in Java with JavaFX and I'm trying to make multiple WAV files play in sync. But when I call the method which makes my clip.start() run for each file, they are completely out of sync.
This is the code for the method I'm calling when I press my button (play).
private Clip playSound(ArrayList<File> files) {
for (File file : files) {
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
} catch (Exception e) {
System.err.print("Sound file open error\n " + e.getMessage());
}
}
return clip;
}
How do I fix this?