我尝试使用Java播放声音时遇到问题;如果我使用使用FileInputStream时发生Java UnsupportedAudioFileException
AudioInputStream soundIn = AudioSystem.getAudioInputStream(new File("./sound.wav"));
获取AudioInputStream,它的工作原理和文件播放正常。但是,如果我用
AudioInputStream soundIn = AudioSystem.getAudioInputStream(new BufferedInputStream(new FileInputStream("./sound.wav")));
我得到
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
我所试图做的是回放,我已经从麦克风录制的音频,我把它保存为一个WAV文件在内存中的字节数组,我不能玩它。但是,如果我将它保存到文件并直接使用File对象,它就会播放。但是,如果使用任何形式的InputStream的,它失败,除此之外,包括当我使用此代码:
AudioInputStream soundIn = AudioSystem.getAudioInputStream(new BufferedInputStream(new ByteArrayInputStream(recorder.getLastRecording())));
凡recorder.getLastRecording()返回一个字节数组。有任何想法吗?