2012-05-22 21 views
2

我正在使用下面的代碼(參考文獻,http://www.java-tips.org/java-me-tips/midp/playing-video-on-j2me-devices.html)。它在'realize()'上失敗,javax.microedition.media.MediaException「無法創建本地播放器」。這裏有什麼問題?
我試着用Eclipse和Netbeans。我是否缺少一些「互聯網」權限或使用任何不正確的編碼,視頻是外部的'mpg'測試資源,並且在通過桌面瀏覽器下載時工作正常。Java Me視頻播放器用http實現錯誤 - MediaException

public void run() 
{ 
    String url = "http://www.fileformat.info/format/mpeg/sample/05e7e78068f44f0ea748855ef33c9f4a/MELT.MPG"; 

    //Append the GUI to a form 
    Form form = new Form("Video on java mobile!"); 
    Display display = Display.getDisplay(this); 
    display.setCurrent(form); 

    try 
    { 
     HttpConnection conn = (HttpConnection)Connector.open(url, 
      Connector.READ_WRITE); 
     InputStream is = conn.openInputStream(); 

     Player p = Manager.createPlayer(is,"video/mpeg"); 
     //I tried the below, but that didn't work either 
     //Player p = Manager.createPlayer(url); 
     p.realize(); 

     //Get the video controller 
     VideoControl video = (VideoControl) p.getControl("VideoControl"); 
     if(video != null) 
     { 
      //Get a GUI to display the video 
      Item videoItem = (Item)video.initDisplayMode(
      VideoControl.USE_GUI_PRIMITIVE, null); 

      form.append(videoItem); 
     } 

     //Start the video   
     p.prefetch(); 
     p.start(); 
    } 
    catch(Exception e) 
    { 
     form.append(url + " Error:" + e.getMessage()); 
    } 

} 

我剛剛開始使用Java,Eclipse,Netbeans。因爲,到處都有類似的樣本,我相信我錯過了一些非常基本的東西。有人可以幫忙嗎?

回答

0

這裏的問題是視頻文件。儘管我的源視頻看起來是「mpeg」,但它並不適合模擬器。經過一番搜索,我發現了一個轉換器,我手動將一些樣品mp4轉換爲「mpeg」。在我嘗試下載並播放這些手動轉換的文件後,它終於與相同的模擬器一起工作。

如果您是新的J2ME/JavaME應用程序(像我一樣),請繼續播放輸入數據源/格式和模擬器,切換仿真器或輸入數據格式是識別不太明顯問題的簡單方法。