使用Personal Java & jmf 作媒體播放器問題!!!!! |
尚未結案
|
AndyC
一般會員 發表:11 回覆:9 積分:4 註冊:2004-07-25 發送簡訊給我 |
動機是要在PDA上能播放媒體影像 引用此處的程式碼 http://www.kupage.com/webdesign/8/20030711/1458230000027nxtk2o1.htm
import javax.media.*; import java.awt.*; import java.awt.event.*; import java.io.*; class mplayer extends Frame implements ActionListener,ControllerListener, ItemListener { Player player; Component vc, cc; boolean first = true, loop = false; String currentDirectory; mplayer (String title) { super (title); addWindowListener(new WindowAdapter () { public void windowClosing (WindowEvent e) { // 用戶點擊窗口系統菜單的關閉按鈕 // 調用dispose以執行windowClosed dispose (); } public void windowClosed (WindowEvent e) { if (player != null) player.close (); System.exit (0); } }); Menu m = new Menu ("文件"); MenuItem mi = new MenuItem ("打開"); mi.addActionListener (this); m.add (mi); m.addSeparator (); /* CheckboxMenuItem cbmi = new CheckboxMenuItem ("循環", false); cbmi.addItemListener (this); m.add (cbmi); m.addSeparator ();*/ mi = new MenuItem ("退出"); mi.addActionListener (this); m.add (mi); MenuBar mb = new MenuBar (); mb.add (m); setMenuBar (mb); setSize (200, 200); setVisible (true); } public void actionPerformed (ActionEvent e) { if (e.getActionCommand ().equals ("退出")) { // 調用dispose以便執行windowClosed dispose (); return; } FileDialog fd = new FileDialog (this, "打開媒體文件",FileDialog.LOAD); fd.setDirectory (currentDirectory); fd.show (); // 如果用戶放棄選擇文件,則返回 if (fd.getFile () == null) return; currentDirectory = fd.getDirectory (); if (player != null) player.close (); try { player = Manager.createPlayer (new MediaLocator ("file:" + fd.getDirectory () + fd.getFile ())); } catch (java.io.IOException e2) { System.out.println (e2); return; } catch (NoPlayerException e2) { System.out.println ("不能找到播放器."); return; } if (player == null) { System.out.println ("無法創建播放器."); return; } first = false; setTitle (fd.getFile ()); player.addControllerListener (this); player.prefetch (); } public void controllerUpdate (ControllerEvent e) { // 調用player.close()時ControllerClosedEvent事件出現。 // 如果存在視覺部件,則該部件應該拆除(為一致起見, // 我們對控制面板部件也執行同樣的操作) if (e instanceof ControllerClosedEvent) { if (vc != null) { remove (vc); vc = null; } if (cc != null) { remove (cc); cc = null; } return; } if (e instanceof EndOfMediaEvent) { if (loop) { player.setMediaTime (new Time (0)); player.start (); } return; } if (e instanceof PrefetchCompleteEvent) { player.start (); return; } if (e instanceof RealizeCompleteEvent) { vc = player.getVisualComponent (); if (vc != null) add (vc); cc = player.getControlPanelComponent (); if (cc != null) add (cc, BorderLayout.SOUTH); pack (); } } public void itemStateChanged (ItemEvent e) { loop = !loop; } public void paint (Graphics g) { if (first) { int w = getSize ().width; int h = getSize ().height; g.setColor (Color.blue); g.fillRect (0, 0, w, h); Font f = new Font ("DialogInput", Font.BOLD, 16); g.setFont (f); FontMetrics fm = g.getFontMetrics (); int swidth = fm.stringWidth ("*** 歡迎 ***"); g.setColor (Color.white); g.drawString ("*** 歡迎 ***",(w - swidth) / 2,(h + getInsets ().top) / 2); } // 調用超類Frame的paint()方法,該paint()方法將調用Frame包含的各個容器 // 和部件(包括控制面板部件)的paint()方法。 super.paint (g); } // 不執行背景清除操作,以免控制面板部件閃爍 public void update (Graphics g) { paint (g); } public static void main (String [] args) { new mplayer ("Media Player"); } }但在 編譯時能通過 執行時 卻無法動作出現錯誤 (附圖) 麻煩高手們協助 我使用的是 j2sdk1.4.2_07 環境變數設定 PATH為 C:\j2sdk1.4.2_07\bin;C:\pjee3.1\bin;C:\pjee3.1\lib 在安裝 JMF 2.1.1e 之後 它多了CLASSPATH 在它後面又加上了下列 C:\pjee3.1\lib;C:\pjee3.1\bin 是不是有多餘的路徑? 還是它會影響在 "命令提示字元"下(如上附圖) 指令中,再指定的路徑? 我把 jmf.jar & swingall_fix.jar 放在c:\pjee3.1\bin 下是否有誤? 附圖中出現的錯誤 不解它是說明何意 |
AndyC
一般會員 發表:11 回覆:9 積分:4 註冊:2004-07-25 發送簡訊給我 |
|
AndyC
一般會員 發表:11 回覆:9 積分:4 註冊:2004-07-25 發送簡訊給我 |
|
AndyC
一般會員 發表:11 回覆:9 積分:4 註冊:2004-07-25 發送簡訊給我 |
|
neoart
版主 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
以下是一般的JDK + JMF,至於PJEE,我正下載來用,試完再跟你說.
=======================================================
我是在自己的pc上安裝JMF,還沒實驗在網路上供人下載的applet會有什麼反應
不過你要先安裝jmf2.1
-->http://java.sun.com/products/java-media/jmf/2.1.1/download.html
下載jmf-2_1_1e-windows-i586.exe,下去安裝在你的pc.
之後,把jmf.jar設定到你的IDE本專案的classes屬性之後.把以下的sample code compile就可以看到好看的了
(沒辦法.不這樣.我真的提不起勁)
以下是我找到的sample
========================================================
import java.applet.Applet; import java.awt.*; import java.lang.String; import java.net.URL; import java.net.MalformedURLException; import java.io.IOException; import javax.media.*; /** * This is a Java Applet that demonstrates how to create a simple * media player with a media event listener. It will play the * media clip right away and continuously loop. * * <!-- Sample HTML * <applet code=TypicalPlayerApplet width=320 height=300> * * </applet> * --> */ public class TypicalPlayerApplet extends Applet implements ControllerListener { // media player Player player = null; // component in which video is playing Component visualComponent = null; // controls gain, position, start, stop Component controlComponent = null; // displays progress during download Component progressBar = null; /** * Read the applet file parameter and create the media * player. */ public void init() { setLayout(new BorderLayout()); // input file name from html param String mediaFile = null; // URL for our media file URL url = null; // URL for doc containing applet URL codeBase = getDocumentBase(); // Get the media filename info. // The applet tag should contain the path to the // source media file, relative to the html page. if ((mediaFile = getParameter("FILE")) == null) Fatal("Invalid media file parameter"); try { // Create an url from the file name and the url to the // document containing this applet. if ((url = new URL(codeBase, mediaFile)) == null) Fatal("Can't build URL for " + mediaFile); // Create an instance of a player for this media if ((player = Manager.createPlayer(url)) == null) Fatal("Could not create player for "+url); // Add ourselves as a listener for player's events player.addControllerListener(this); } catch (MalformedURLException u) { Fatal("Invalid media file URL!"); } catch(IOException i) { Fatal("IO exception creating player for "+url); }catch(Exception exp){ exp.printStackTrace(); } // This applet assumes that its start() calls // player.start().This causes the player to become // Realized. Once Realized, the Applet will get // the visual and control panel components and add // them to the Applet. These components are not added // during init() because they are long operations that // would make us appear unresposive to the user. } /** * Start media file playback. This function is called the * first time that the Applet runs and every * time the user re-enters the page. */ public void start() { // Call start() to prefetch and start the player. if (player != null) player.start(); } /** * Stop media file playback and release resources before * leaving the page. */ public void stop() { if (player != null) { player.stop(); player.deallocate(); } } /** * This controllerUpdate function must be defined in order * to implement a ControllerListener interface. This * function will be called whenever there is a media event. */ public synchronized void controllerUpdate(ControllerEvent event) { // If we're getting messages from a dead player, // just leave if (player == null) return; // When the player is Realized, get the visual // and control components and add them to the Applet if (event instanceof RealizeCompleteEvent) { if ((visualComponent = player.getVisualComponent()) != null) add("Center", visualComponent); if ((controlComponent = player.getControlPanelComponent()) != null) add("South",controlComponent); // force the applet to draw the components validate(); } else if (event instanceof CachingControlEvent) { // Put a progress bar up when downloading starts, // take it down when downloading ends. CachingControlEvent e = (CachingControlEvent) event; CachingControl cc = e.getCachingControl(); long cc_progress = e.getContentProgress(); long cc_length = cc.getContentLength(); // Add the bar if not already there ... if (progressBar == null) if ((progressBar = cc.getProgressBarComponent()) != null) { add("North", progressBar); validate(); } // Remove bar when finished ownloading if (progressBar != null) if (cc_progress == cc_length) { remove (progressBar); progressBar = null; validate(); } } else if (event instanceof EndOfMediaEvent) { // We've reached the end of the media; rewind and // start over player.setMediaTime(new Time(0)); player.start(); } else if (event instanceof ControllerErrorEvent) { // Tell TypicalPlayerApplet.start() to call it a day player = null; Fatal (((ControllerErrorEvent)event).getMessage()); } } void Fatal (String s) { // Applications will make various choices about what // to do here. We print a message and then exit System.err.println("FATAL ERROR: " + s); throw new Error(s); // Invoke the uncaught exception // handler System.exit() is another // choice } }================================================================== html 崁入: ======================================== <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=Big5"> <title> HTML Test Page </title> </head> <body> mediatest.TypicalPlayerApplet will appear below in a Java enabled browser. <applet codebase = "." code = "mediatest.TypicalPlayerApplet.class" name = "TestApplet" width = "400" height = "300" hspace = "0" vspace = "0" align = "middle" FILE= "file:///G:/AV區/mov09.mpg" <---別跟我要這檔.已經在本實驗後自行刪除了 > </applet> </body> </html> =========================================至於你是寫成JFrame的方式,應該更沒問題了 至於在PDA上.請參考以下的討論: http://forum.java.sun.com/thread.jspa?forumID=28&threadID=304316 本機的網頁上是可以看到有在play. 發表人 - neoart 於 2005/04/04 03:37:42 |
AndyC
一般會員 發表:11 回覆:9 積分:4 註冊:2004-07-25 發送簡訊給我 |
3Q neoart 版主的協助!!
在一般java環境是可以播放影像的
我在使用j2sdk1.4.2_07 + pjee3.1 下出現這樣↓
的錯誤~
我再try 以jdk 1.1.8 + pjee 3.0.2
則出現
找不到"awtLocalization_zh_TW"此class的錯誤,此時僅能聽到聲音,影像無法呈現
now 既時我從1.4.2_07 中找出該class,但它卻視若無睹,仍出現找不到的錯誤@@! 發表人 - AndyC 於 2005/04/06 23:03:53
|
neoart
版主 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
Dear AndyC:
首先在此對於無法解決你的問題,感到非常抱歉,畢竟,JME/personal java不是敝人專擅所在
所以我正打算調一台iPAQ來試.
你有沒有試過J2ME的jbuilder 套件 -- "Mobile Set"呢?
那一套系列是可以模擬手機的環境放映mpeg的方式.
至於"Unable To Handle Format: MPEG...."的訊息.我也有在一種請況看過:
PC A 為web server,PC B 從 A 的站台的url打開applet viewer去看jmf放映,
在沒有安裝 "jmf-2_1_1e-windows-i586.exe" 時,就會在java 主控台看到這樣的錯誤訊息.
所以,在下推敲是---PJEE跟JMF之間沒有關連到,要不要把jmf的DLL & JARs copy到 PJEE去呢?
畢竟,模擬器還是有差的.有機會拿到PDA,也許可以試出來.
|
AndyC
一般會員 發表:11 回覆:9 積分:4 註冊:2004-07-25 發送簡訊給我 |
|
AndyC
一般會員 發表:11 回覆:9 積分:4 註冊:2004-07-25 發送簡訊給我 |
錯誤訊息似乎是代表著找不到jmfjawt.dll檔
在網路曾找過相似的訊息,但不一定代表是這個錯誤
但是我也只能朝著這個方向去debug
有試過用System.load以及System.loadLibrary的方式去
但總是出現jmfjawt cannot find in shared path
另外試過JNI的方式去load dll檔
但是,似乎有點矛盾...
以JNI來講....我們得自己用C撰寫DLL檔
但是...DLL已經存在,因為是jmf提供的....
一般Java執行jmfjawt要找的.h檔..我找不到..也不了解
因此在這邊整個卡住了...
是否能有辦法去Load 這個jmfjawt.dll的方法呢??
能否請高手們指導一下
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |