2012-10-09 19 views
0

我試圖啓動我的我的代碼,並開始播放。但我不能那樣做。我不能啓動播放器在我的代碼

import javax.media.*; 
import java.io.*; 

public class MP3Player { 

    public static void main(String[] args) throws Exception { 
     File file = new File("c://player/trigger.mpg"); 
     MediaLocator mrl = new MediaLocator(file.toURL()); 
     Player player = Manager.createPlayer(mrl); 
     player.start(); 
    } 

} 

[由菲利普編輯] 據原作者註釋,Netbeans的打印以下錯誤消息:

Unable to handle format: MPEG, 160x120, FrameRate=30.0, Length=28800 Failed to realize: 
[email protected] Error: Unable to realize 
[email protected] BUILD SUCCESSFUL (total time: 1 second) 

[由菲利普/編輯]

+0

擴展是缺少/路徑中一個錯字? –

+0

「不能這樣做」=?你有錯誤嗎?你的電腦爆炸了嗎? –

+0

我收到了來自Netbeans的此消息 – Alex

回答

1

我根本不認識JMF播放器,但我認爲問題在於代碼在發出命令後立即退出,終止任何其他線程...

我想嘗試插入了Thread.sleep(1000); player.start();之後:

public class MP3Player { 
    public static void main(String[] args) throws Exception 
    {  
     File file = new File("c:/player/trigger.mpg");  
     MediaLocator mrl = new MediaLocator(file.toURL());  
     Player player = Manager.createPlayer(mrl);  
     player.start(); 
     Thread.sleep(1000); 
    } 
} 

如果現在聽到MP3的第一秒,那就是問題所在。

編輯此外,有人指出,與斜線問題,路徑應該是正確的太多,但斜線是不缺的,但是有相當一個也太多了吧......

EDIT2好的,我錯誤讀取了mp3的mp3格式,並且發佈了錯誤消息:JMF不支持該視頻格式,因此您需要編解碼器。

這可能會有幫助:Tek-tips: Play MPEG-4 movie with JMF?

0

Unable to handle format: MPEG, 160x120, FrameRate=30.0 這是無法發揮視頻流它創立。從描述和代碼的名稱,該文件預計將只包含音頻流的壓縮格式MP3(MPEG-1音頻層III)的的.MPG可能包含很多不同的MPEG格式