javax.media包 我想用java编写一个播放器,需要一个javax.media包,谁能传给我,并且教我怎么放置,谢谢。邮箱:[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Java推出的JMF(Java Media Framework)之后标着Java进入了多媒体时代,如果你想编写能播放视频的Java程序,必须下载sun公司的JMF2.1(或者更高的版本),它为我们提供了编写多媒体必须的包:java.media没有安装JFM的在编译*.java的时候会提示找不到java.media包java JMF的配置方法1.首先去sun公司的主页去下载安装包2.下载得到一个名为jdk-6u12-windows-i586-p 的文件3.双击安装,默认的安装路径是C:\Program Files\JMF2.1.1e(可以根据自己的需要改变这个路径)4.安装后,需要配置下面的几个变量(vista系统和XP相同),下面以vista系统为例子a.点击我的电脑--->属性--->高级系统设置--->环境变量b.找到CLASSPATH,分别增加jmf.jar和sound.jarC:\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);elseframe.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();}} } 注:本文转自别人的博客地址:http://blog.163.com/penghaimin138@126/blog/static/1336243962009102983814892/ 再问一个关于线程锁的问题,谢谢各路好汉! 代码测试问题 如何拷贝文件内容到当前文件的末尾 请教内部类一般有那些作用? 请高手指点,如果hashmap不知道object key 如何得到hashmap里面的值? 请高手帮我看看关于内嵌静态类的问题,谢谢 Java创建字符串常量内存分析 getContentPane() 是干什么的 请问谁有利用java在oracle数据库中读取图片并显示的例子,或者文档,十分感谢,急,谢谢 几个关于短信的问题 给定10个数字,列出其所有组合!不能重复 java string问题 很小很纠结……在线求帮助
没有安装JFM的在编译*.java的时候会提示找不到java.media包
java JMF的配置方法1.首先去sun公司的主页去下载安装包
2.下载得到一个名为jdk-6u12-windows-i586-p 的文件3.双击安装,默认的安装路径是C:\Program Files\JMF2.1.1e(可以根据自己的需要改变这个路径)4.安装后,需要配置下面的几个变量(vista系统和XP相同),下面以vista系统为例子a.点击我的电脑--->属性--->高级系统设置--->环境变量b.找到CLASSPATH,分别增加jmf.jar和sound.jarC:\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();
}
}
}
注:本文转自别人的博客
地址:http://blog.163.com/penghaimin138@126/blog/static/1336243962009102983814892/