于是想到了jmf+applet。jar包地址如下:
http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jmf-2_1_1e-alljava.zip?BundledLineItemUUID=CgGJ_hCwhvoAAAEsmjYAHJ_E&OrderID=536J_hCwL7UAAAEsgTYAHJ_E&ProductID=X4zACUFBcakAAAEYzNI5AXis&FileName=/jmf-2_1_1e-alljava.zip
考虑到某些人看到这么长的地址不放心(比如我),可以到
https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewFilteredProducts-SingleVariationTypeFilter
下载
再不放心,可以去
http://www.oracle.com/technetwork/java/javase/download-142937.html

需要导入的包包有:
import java.applet.*; import java.awt.*; import java.net.*; import java.io.*; import javax.media.*;
然后类的屁股加上
extends Applet implements ControllerListener
正文开始:
Player player = null;
public void init() { URL url = null; try { //getDocumentBase() 是获取documentBase的路径,我的是:${工程路径}/bin/ url=new URL(getDocumentBase(),"文件名"); player = Manager.createPlayer(url); if (player != null) { player.addControllerListener(this); } public void start() { if (player != null) player.prefetch(); } public void stop() { if (player != null) { player.stop(); player.deallocate(); } } public synchronized void controllerUpdate(ControllerEvent event) { Component visualComponent = null; Component controlComponent = null; if (event instanceof RealizeCompleteEvent) { if ((visualComponent = player.getVisualComponent()) != null) { add("Center", visualComponent); } if ((controlComponent = player.getControlPanelComponent()) != null) { if (visualComponent != null) add("South", controlComponent); else add("Center", controlComponent); } validate(); } else if (event instanceof PrefetchCompleteEvent) { player.start(); } }
如果想手动设置url,请以下面的方式写:
URL u = new URL("file:${目录}/");
比如file:c:/abc/ 其中前缀file:和后面的“/”不可少
另:支持的格式比较少,好容易在电脑里翻出了一个《太阁立志传5》的视频文件可以播放,想尝试的可以下载这个文件试试。
有些AVI和MPG可能会因为文件格式的问题而无法播放。
只能有待高手解决了。