你如何在Eclipse中使用WAV文件?

时间:2011-11-27 01:43:56

标签: java swing javasound

我一直在努力为我一直在做的项目添加音频。我在这里找到了一些HTML代码,它也应该与文件一起工作,但它一直在说:

 "Exception in thread "main" javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file    at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)  at LoopSound.main(LoopSound.java:15)"

代码:

public class LoopSound {

    public static void main(String[] args) throws Throwable  {
        File file = new File("c:\\Users\\rabidbun\\Pictures\\10177-m-001.wav");
        Clip clip = AudioSystem.getClip();
        // getAudioInputStream() also accepts a File or InputStream
        AudioInputStream wav = AudioSystem.getAudioInputStream( file );
        clip.open(wav);
        // loop continuously
        clip.loop(-1000);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                // A GUI element to prevent the Clip's daemon Thread
                // from terminating at the end of the main()
                JOptionPane.showMessageDialog(null, "Close to exit!");
            }
        });
    }
}

代码有什么问题?

0 个答案:

没有答案
相关问题