我正在尝试加载 MP3 文件。我的类路径中有 jmf.jar(windows 版本),并试图通过 Eclipse 运行我的类。但是在尝试运行时出现此错误。
我从 oracle 站点下载并设置了这个版本的 JMF:
我正在使用 Oracle 的 Java 7(通过 Eclipse)
错误:
javax.sound.sampled.UnsupportedAudioFileException:
could not get audio input stream from input stream
at
javax.sound.sampled.AudioSystem.getAudioInputStream
(Unknown Source)
at
org.berlin.sound.WaveformDisplaySimulator.main
(WaveformDisplaySimulator.java:47)
这是代码:
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import javax.media.Codec;
import javax.media.Format;
import javax.media.PlugInManager;
import javax.media.format.AudioFormat;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
public static void main(final String[] args) {
try {
System.out.println(System.getProperty("java.version"));
final String MP3 = "com.sun.media.codec.audio.mpa.JavaDecoder";
Codec mp3 = (Codec) Class.forName(MP3).newInstance();
final Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
final Format input2 = new AudioFormat(AudioFormat.MPEG);
final Format output = new AudioFormat(AudioFormat.LINEAR);
PlugInManager.addPlugIn(
"com.sun.media.codec.audio.mpa.JavaDecoder",
new Format[]{ input1, input2 },
new Format[]{ output },
PlugInManager.CODEC
);
final AudioFileFormat.Type [] types = AudioSystem.getAudioFileTypes();
for (final AudioFileFormat.Type t : types) {
System.out.println("Returning Type : " + t);
} // End of the for //
final String PATH = "C:\\Users\\Downloads\\soundcloud2.mp3";
final File file = new File(PATH);
final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new BufferedInputStream(new FileInputStream(file)));
} catch (final Exception e) {
e.printStackTrace();
}
} // End of the method //