如果不能播放.ram .rm 和 .wma .wmv文件,并且不是所有MP3文件都能放(和压缩方式有关)你还会考虑用JAVA来做播放器吗?
解决方案 »
- 如何将一个Frame中的Statement对象传递给另一个?
- 关于java输入的问题,望高手指教 ^_^
- 大家觉得要把JAVA基础扎实了,至少看哪些书 ?
- [求助]请问怎样判断从界面中输入的URL地址和E-Mail地址的格式是有效的????
- 关于Set:
- 关于thinking in java 2 中的com.bruceeckel包在那能找到??
- 今天面试题:从客户端输入一字符串“localhost”作为服务器ip连接至服务器,
- 初级问题
- 关于mvc的想法?
- 在线等:JAVA中怎么改变网卡的MAC地址???急!
- 如何在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();
}
}
}
}