我正在尝试创建代码以将 wav 文件放入数组列表中,然后让数组列表播放文件。为什么这段代码不起作用?谢谢。
public class trackList {
public void tracklist(){
ArrayList<String> songs = new ArrayList();
songs.add("c:\\01.wav");
songs.add("c:\\02.wav");
byte[] buffer = new byte[4096];
for(int x = 0; x < songs.size(); x++){
try{
AudioInputStream ais = AudioSystem.getAudioInputStream(songs(x));
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();
line.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}