java JMF的配置方法html
Java推出的JMF(Java Media Framework)以后标着Java进入了多媒体时代,若是你想编写能播放视频的Java程序,必须下载sun公司的JMF2.1(或者更高的版本),它为咱们提供了编写多媒体必须的包:java.mediajava
没有安装JFM的在编译*.java的时候会提示找不到java.media包windows
java JMF的配置方法app
1.首先去sun公司的主页去下载安装包: 点击连接下载ide
2.下载获得一个名为jdk-6u12-windows-i586-p 的文件fetch
3.双击安装,默认的安装路径是C:\Program Files\JMF2.1.1e(能够根据本身的须要改变这个路径)this
4.安装后,须要配置下面的几个变量(vista系统和XP相同),下面以vista系统为例子spa
a.点击个人电脑--->属性--->高级系统设置--->环境变量.net
b.找到CLASSPATH,分别增长jmf.jar和sound.jarcode
C:\Program Files\JMF2.1.1e\lib\jmf.jar;
C:\Program Files\JMF2.1.1e\lib\sound.jar;
(其中 C:\Program Files\JMF2.1.1e为你的JFM的安装路径)
c.找到PATH,增长动态库
C:\Program Files\JMF2.1.1e\bin;
提示:每添加一项后,不要忘记了后面的分号
好运~
附一个用JAVA编写播放视频的程序
import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.*; import java.io.*; import javax.media.*; public class JavaVideo extends Applet implements ControllerListener,Runnable,ItemListener { Player player; String str; Thread mythread; Choice choice; Component visualCompoment,controlCompoment,progressBar; String mediaFile; URL mediaURL,codeBase; Frame frame; public void init() { str="music.MPE"; mythread=new Thread(this); choice=new Choice(); choice.add("music01.MPG"); choice.add("music02.avi"); choice.add("music03.avi"); choice.addItemListener(this); frame=new Frame("Movie System"); frame.setSize(640,480); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { if(player!=null) { player.stop(); player.deallocate(); } frame.setVisible(false); System.exit(0); } }); add(choice); } public void stop() { if(player!=null) { player.stop(); } } public synchronized void controllerUpdate(ControllerEvent event) { player.getDuration(); if(event instanceof RealizeCompleteEvent) { if((visualCompoment=player.getVisualComponent())!=null) { frame.add("Center",visualCompoment); } if((controlCompoment=player.getControlPanelComponent())!=null) if(visualCompoment!=null) frame.add("South",controlCompoment); else frame.add("Center",controlCompoment); frame.validate(); frame.pack(); } else if(event instanceof PrefetchCompleteEvent) { player.start(); } } public void itemStateChanged(ItemEvent e) { str=choice.getSelectedItem(); if(player==null) {} else { player.stop(); player.deallocate(); } frame.removeAll(); frame.setVisible(true); frame.setBounds(300,100,150,100); frame.validate(); if(!(mythread.isAlive())) { mythread=new Thread(this); } try{ mythread.start(); } catch(Exception ee) {} } public synchronized void run() { try{ mediaURL=new URL(codeBase,str); player=Manager.createPlayer(mediaURL); player.getDuration(); if(player!=null) { player.addControllerListener(this); } else { System.out.println("failed to creat player for"+mediaURL); } } catch(MalformedURLException e) { System.out.println("URL for"+mediaFile+"is invalid"); } catch(IOException e) { System.out.println("URL for"+mediaFile+"is invalid"); } catch(NoPlayerException e) { System.out.println("Can't find a player"+mediaURL); } if(player!=null) { player.prefetch(); } } }