我正在尝试使用Java Sound APIInputStream
将包含数据从 MP3 文件转换为。AudioInputStream
Exception
但是,当我尝试这样做时,我一直遇到一个。
这是导致问题的方法:
public static int[][] getAmpFromInputStream(InputStream is) throws Exception{
BufferedInputStream bs = new BufferedInputStream(is);
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(bs);
byte[] bytes = new byte[(int) (audioInputStream.getFrameLength()) * (audioInputStream.getFormat().getFrameSize())];
audioInputStream.read(bytes);
// Get amplitude values for each audio channel in an array.
return getUnscaledAmplitude(bytes, 1);
}
抛出的Exception
是:
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at PitchChanger.getAmpFromInputStream(PitchChanger.java:27)
at GUI$PlayMP3Thread.silly(GUI.java:128)
at GUI$PlayMP3Thread.run(GUI.java:115)
at java.lang.Thread.run(Unknown Source)
然而,这让我感到困惑,因为我用它InputStream
来玩Javazoom.jl.player.Player
,它在那里工作得很好。
那么为什么不能InputStream
转换成一个AudioInputStream
?
Java Sound 不支持 MP3 文件格式吗?