-2

我正在尝试创建代码以将 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();

                }
        }                       
    } 
}
4

1 回答 1

6

不是Java专家,但可能是这样的:

AudioInputStream ais = AudioSystem.getAudioInputStream(songs(x));

一定是

AudioInputStream ais = AudioSystem.getAudioInputStream(songs.get(x));
于 2013-04-12T18:41:38.137 回答