SWT+JMF乱真windows播放器
SWT的最大好处是windows具有窗口风格,把SWT与JMF结合使用,windows的外框,java的播放器,你觉得我这个想法如何?
如果你要运行我的代码,你必须安装JMF2.1.1e并且将swt的jar文件导入(记得要将swt-win32-2135.dll放在执行路径下)。
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Panel;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.media.ConfigureCompleteEvent;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.EndOfMediaEvent;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.RealizeCompleteEvent;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.internal.awt.win32.SWT_AWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* @author
* <a href="mailto:[email protected]">刘洋</a>
* 2003-7-17 19:34:38
*/
public class SWTPlayer implements ControllerListener {
public static void main(String[] args) {
SWTPlayer sp = new SWTPlayer();
sp.play();
}
private boolean configured =false;
private boolean realized = false;
Player player;
Panel panel;
public void play(){
Display display = new Display ();
Shell shell = new Shell(display,SWT.MAX);
shell.setSize(320,240);
shell.setText("你好SWT");
panel = SWT_AWT.new_Panel(shell);
URL url = null;
try {
url = new URL("file:/D:/video/jboss.mpeg");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
player = Manager.createPlayer(url);
} catch (NoPlayerException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
player.addControllerListener(this);
player.realize();
while (! realized) {
try {
Thread.sleep(100L);;
} catch (InterruptedException e) {
// ignore
}
}
panel.setLayout(new BorderLayout());
panel.add(player.getVisualComponent(),BorderLayout.CENTER);
Component cpc = player.getControlPanelComponent();
if (cpc != null) {
panel.add(cpc,BorderLayout.SOUTH);
} else {
}
player.start();
shell.open ();
Window win;
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
/* (non-Javadoc)
* @see javax.media.ControllerListener#controllerUpdate(javax.media.ControllerEvent)
*/
public void controllerUpdate(ControllerEvent evt) {
if (evt instanceof RealizeCompleteEvent) {
realized = true;
} else if (evt instanceof ConfigureCompleteEvent) {
configured = true;
} else if (evt instanceof EndOfMediaEvent) {
} else {
}
}
}
SWT的最大好处是windows具有窗口风格,把SWT与JMF结合使用,windows的外框,java的播放器,你觉得我这个想法如何?
如果你要运行我的代码,你必须安装JMF2.1.1e并且将swt的jar文件导入(记得要将swt-win32-2135.dll放在执行路径下)。
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Panel;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.media.ConfigureCompleteEvent;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.EndOfMediaEvent;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.RealizeCompleteEvent;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.internal.awt.win32.SWT_AWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* @author
* <a href="mailto:[email protected]">刘洋</a>
* 2003-7-17 19:34:38
*/
public class SWTPlayer implements ControllerListener {
public static void main(String[] args) {
SWTPlayer sp = new SWTPlayer();
sp.play();
}
private boolean configured =false;
private boolean realized = false;
Player player;
Panel panel;
public void play(){
Display display = new Display ();
Shell shell = new Shell(display,SWT.MAX);
shell.setSize(320,240);
shell.setText("你好SWT");
panel = SWT_AWT.new_Panel(shell);
URL url = null;
try {
url = new URL("file:/D:/video/jboss.mpeg");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
player = Manager.createPlayer(url);
} catch (NoPlayerException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
player.addControllerListener(this);
player.realize();
while (! realized) {
try {
Thread.sleep(100L);;
} catch (InterruptedException e) {
// ignore
}
}
panel.setLayout(new BorderLayout());
panel.add(player.getVisualComponent(),BorderLayout.CENTER);
Component cpc = player.getControlPanelComponent();
if (cpc != null) {
panel.add(cpc,BorderLayout.SOUTH);
} else {
}
player.start();
shell.open ();
Window win;
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
/* (non-Javadoc)
* @see javax.media.ControllerListener#controllerUpdate(javax.media.ControllerEvent)
*/
public void controllerUpdate(ControllerEvent evt) {
if (evt instanceof RealizeCompleteEvent) {
realized = true;
} else if (evt instanceof ConfigureCompleteEvent) {
configured = true;
} else if (evt instanceof EndOfMediaEvent) {
} else {
}
}
}