我有一个字符串数组列表,它一个一个地遍历这个列表,它应该播放 wav 文件。
在这一行“AudioInputStream ais = AudioSystem.getAudioInputStream(music(x));” 无法识别音乐,它显示“找不到符号”。此外 (music.get(x)) 不起作用。然后整行加下划线,说明其不适用。我需要做什么?谢谢。
String trackName;
ArrayList<String> music = new ArrayList();
music.add("c:\\01.wav");
music.add("c:\\02.wav");
music.add("c:\\03.wav");
music.add("c:\\04.wav");
byte[] buffer = new byte[4096];
for(int x = 0; x < music.size(); x++){
try{
AudioInputStream ais = AudioSystem.getAudioInputStream(music(x));
trackName = "The Current Track is " + music.get(x);
System.out.println(trackName);
AudioFormat format = ais.getFormat();
SourceDataLine line = AudioSystem.getSourceDataLine(format);
line.open(format);
line.start();
while (ais.available() > 0) {
int len = ais.read(buffer);
line.write(buffer, 0, len);
}
line.drain(); //wait for the buffer to empty before closing the line
line.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}