怎样用java做简单的播放器? 如果不能播放.ram .rm 和 .wma .wmv文件,并且不是所有MP3文件都能放(和压缩方式有关)你还会考虑用JAVA来做播放器吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我只要求能播放MPEG图象就够了。 先下载jmf.jar使用javax.media包就可以了。看看我的例子吧import java.awt.*;import java.awt.event.*;import java.applet.*;import java.net.*;import java.io.*;import javax.media.*;/** * <p>Title: 雷堂祖聊天软件</p> * <p>Description: 雷堂祖</p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: 雷堂祖</p> * @author 雷堂祖([email protected]) * @version 1.0 */public class BasicPlayer extends Applet implements ControllerListener{ boolean isStandalone = false; String mediaFile; //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } Player player = null; Component visualComponent = null; //Construct the applet public BasicPlayer() { } //Initialize the applet public void init() { try { mediaFile = this.getParameter("MediaFile", ""); } catch(Exception e) { e.printStackTrace(); } try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { URL mediaURL = null; setLayout(new BorderLayout()); if(mediaFile == null) { System.err.print("MediaFile not present."); System.err.println("Required parameter is 'MediaFile'"); } else { try{ mediaURL = new URL(this.getDocumentBase(),mediaFile); player = Manager.createPlayer(mediaURL); if(player !=null) { player.addControllerListener(this); }else{ System.err.println("failed to create player for "+mediaFile); } } catch(IOException e) { System.err.println("URL for "+mediaFile +" is invalid"); } catch(NoPlayerException e) { System.err.println("could not find a player for "+mediaURL); } } } //Start the applet public void start() { if(player != null) { player.prefetch(); } } //Stop the applet public void stop() { if(player != null) { player.stop(); player.deallocate(); } } //Destroy the applet public void destroy() { } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { String[][] pinfo = { {"MediaFile", "String", "./images/0050.mpg"}, }; return pinfo; } public void componentAdded(ContainerEvent e) { /**@todo: Implement this java.awt.event.ContainerListener method*/ //throw new java.lang.UnsupportedOperationException("Method componentAdded() not yet implemented."); } public void componentRemoved(ContainerEvent e) { /**@todo: Implement this java.awt.event.ContainerListener method*/ //throw new java.lang.UnsupportedOperationException("Method componentRemoved() not yet implemented."); } public synchronized void controllerUpdate(ControllerEvent parm1) { /**@todo: Implement this javax.media.ControllerListener method*/ //throw new java.lang.UnsupportedOperationException("Method controllerUpdate() not yet implemented."); if(parm1 instanceof RealizeCompleteEvent) { if((visualComponent = player.getVisualComponent()) != null) { this.add("Center",visualComponent); } this.validate(); }else{ if(parm1 instanceof PrefetchCompleteEvent) { player.start(); } } }} 上面的程序就支持internet文件,修改mediafile即可 基于TCP连接的多个程序批次连接互发消息 关于JApplet的问题求大神指点。。 关于while()循环的问题 JAVA如何搜索WINDOWS的某个文件,并得到该文件的路径? 怎样用jsp把word表格的数据读如oracle数据库,各位大虾指点 可以这样定义整形数组a1和a2吗:int [ ] a1,a2; 静态字段的应用 请教各位一个有关包的傻的可爱的问题,马上给分!!! jbuilder中开发EntityBean 谁能帮帮我(关于jdbc的问题) 如何在JLabel中显示换行,制表符? 怎样改变tomcat的发布目录,比如c:\esuit,并且去掉端口号....
使用javax.media包就可以了。
看看我的例子吧
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
import java.io.*;
import javax.media.*;/**
* <p>Title: 雷堂祖聊天软件</p>
* <p>Description: 雷堂祖</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: 雷堂祖</p>
* @author 雷堂祖([email protected])
* @version 1.0
*/public class BasicPlayer extends Applet implements ControllerListener
{
boolean isStandalone = false;
String mediaFile;
//Get a parameter value
public String getParameter(String key, String def)
{
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
Player player = null;
Component visualComponent = null; //Construct the applet
public BasicPlayer()
{
}
//Initialize the applet
public void init()
{
try
{
mediaFile = this.getParameter("MediaFile", "");
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception
{
URL mediaURL = null; setLayout(new BorderLayout());
if(mediaFile == null)
{
System.err.print("MediaFile not present.");
System.err.println("Required parameter is 'MediaFile'");
}
else
{
try{
mediaURL = new URL(this.getDocumentBase(),mediaFile); player = Manager.createPlayer(mediaURL); if(player !=null)
{
player.addControllerListener(this);
}else{
System.err.println("failed to create player for "+mediaFile);
}
}
catch(IOException e)
{
System.err.println("URL for "+mediaFile +" is invalid");
}
catch(NoPlayerException e)
{
System.err.println("could not find a player for "+mediaURL);
}
} }
//Start the applet
public void start()
{
if(player != null)
{
player.prefetch();
}
}
//Stop the applet
public void stop()
{
if(player != null)
{
player.stop();
player.deallocate();
}
}
//Destroy the applet
public void destroy()
{
}
//Get Applet information
public String getAppletInfo()
{
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo()
{
String[][] pinfo =
{
{"MediaFile", "String", "./images/0050.mpg"},
};
return pinfo;
}
public void componentAdded(ContainerEvent e)
{
/**@todo: Implement this java.awt.event.ContainerListener method*/
//throw new java.lang.UnsupportedOperationException("Method componentAdded() not yet implemented.");
}
public void componentRemoved(ContainerEvent e)
{
/**@todo: Implement this java.awt.event.ContainerListener method*/
//throw new java.lang.UnsupportedOperationException("Method componentRemoved() not yet implemented.");
}
public synchronized void controllerUpdate(ControllerEvent parm1)
{
/**@todo: Implement this javax.media.ControllerListener method*/
//throw new java.lang.UnsupportedOperationException("Method controllerUpdate() not yet implemented.");
if(parm1 instanceof RealizeCompleteEvent)
{
if((visualComponent = player.getVisualComponent()) != null)
{
this.add("Center",visualComponent);
}
this.validate();
}else{
if(parm1 instanceof PrefetchCompleteEvent)
{
player.start();
}
}
}
}