The premise is that I am inputting music notes and the program plays the according piano notes. The only issue is that the first note works, but the rest of the notes do not play. So, if I input "ABC," note A will play but notes B and C will not. Is it because the file is static?
public class SnapMusic {
static File file = new File("");
static void setUp() {
try {
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(file));
clip.start();
Thread.sleep(clip.getMicrosecondLength());
}
catch (Exception e) {
System.err.println(e.getMessage());
}
}
public static void main (String[] arrgs) {
Scanner scan = new Scanner(System.in);
String notes = scan.next();
for (int i = 0; i < notes.length(); i++) {
if (notes.charAt(i) == 'A') {
file = new File("src/musictranslator/MidA.wav");
setUp();
}
else if (notes.charAt(i) == 'B') {
file = new File("src/musictranslator/MidB.wav");
setUp();
}
else if (notes.charAt(i) == 'C') {
file = new File("src/musictranslator/MidC.wav");
setUp();
}
else if (notes.charAt(i) == 'D') {
file = new File("src/musictranslator/MidD.wav");
setUp();
}
}