[英]can't play audio File with JMF
我在使用JMF播放MP3文件時遇到問題,它顯示以下錯誤:
Error:
Unable to realize com.sun.media.amovie.AMController@80669d Exception in thread "main"
javax.media.CannotRealizeException at javax.media.Manager.blockingCall(Manager.java:2005) at
javax.media.Manager.createRealizedPlayer(Manager.java:528) at tp.Main.main(Main.java:44)
Error value: 80070020
這是我的代碼:
public class Main {
public static void main(String[] args) throws NoPlayerException, CannotRealizeException, MalformedURLException, IOException, URISyntaxException {
Fenetre F1 = new Fenetre();
F1.setVisible(true);
InputStream is = Main.class.getClass().getResourceAsStream("/data/gmu.mp3");
File temp=File.createTempFile("temp", ".mp3");
OutputStream os = new FileOutputStream(temp);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = is.read(bytes)) != -1) {
os.write(bytes, 0, read);
}
final Player p=Manager.createRealizedPlayer(temp.toURI().toURL());
p.start();
while(true){
if(p.getMediaTime().getSeconds()==p.getDuration().getSeconds()){
p.stop();
p.setMediaTime(new Time(0));
p.start();
}
}
}
}
通常,如果我不使用InputStream並簡單地使用
File f =new File(Main.class.getResource("/data/gmu.mp3").getFile());
final Player p=Manager.createRealizedPlayer(temp.toURI().toURL());
但是這種方式在打包我的JAR文件時不起作用,所以我嘗試使用InputStream,目的是制作帶有工作音樂的JAR
實際上,我只需要將我的MP3文件轉換為WAV即可! 我不知道為什么MP3臨時文件捕獲了播放器異常,但是WAV沒出錯。 這不是我真正想要的答案,因為WAV文件占用更多空間,但至少可以使用。
我還嘗試了OGG格式,這使MP3出現了同樣的問題...
任何其他答案,建議或討論均受到歡迎。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.