我想加載MP3文件。我在我的類路徑中有jmf.jar(windows版本),並試圖通過Eclipse運行我的類。但是在嘗試運行時遇到此錯誤。使用Java API和JMF播放/加載mp3,錯誤不支持的格式
我下載並從Oracle站點設置這個版本的JMF的:
我與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 //
你是否還有MP3庫插件? http://www.oracle.com/technetwork/java/javase/download-137625.html –
'無法從輸入流獲取音頻輸入流'不是所有的MP3都是相同的。嘗試使用其他MP3,尤其是舊的/簡單的MP3,可以在這裏找到(http://pscode.org/media/#sound)(該頁面目前很慢)。 –
我沒有看到mp3plugin.jar。當我點擊上面的鏈接時,我會重定向到JMF下載站點,該站點並不專門具有mp3plugin。另外,我還發布了JMStudio並能夠加載MP3。所以它一定是我的代碼。我不知道要改變什麼。另外,JavaDecoder類不在我的類路徑中,我找不到它。 –