我正在使用下面的代碼(參考文獻,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。因爲,到處都有類似的樣本,我相信我錯過了一些非常基本的東西。有人可以幫忙嗎?