SWT可以内嵌系统控件,这样理论就可以打开任何格式的文件。
下面代码是一个全屏的多媒体播放器。
下面代码是一个全屏的多媒体播放器。
package
com.kompakar.tutorial.swt.video;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/** */ /**
*
* @author Benewu(at)gmail.com
* SWT Player
*/
public class SWTVideoPlayer ... {
public static void main(String[] args) ...{
Display display = new Display();
//设置全屏shell
Shell shell = new Shell(display,SWT.ON_TOP | SWT.TOOL);
// Shell shell = new Shell(display); //带title的窗口
shell.setText("SWT Video Player");
shell.setSize(640, 480);
shell.setLayout(new FillLayout());
OleFrame frm = new OleFrame(shell, SWT.NONE);
OleClientSite site = new OleClientSite(frm, SWT.NONE,
"MediaPlayer.MediaPlayer");
OleAutomation auto = new OleAutomation(site);
int[] ids = null;
ids = auto.getIDsOfNames(new String[] ...{ "Open" });
String mediaFilePath = "D:/Program Files/eMule/Incoming/South.Park.S11E05.Fantastic.Easter.Special.DSR.XviD-CRiMSON.avi";
auto.invoke(ids[0], new Variant[] ...{ new Variant(mediaFilePath) });
new SWTVideoPlayer().setOleAutomationPropertiy(auto);
ids = auto.getIDsOfNames(new String[] ...{ "Play" });
auto.invoke(ids[0]);
shell.open();
while (!shell.isDisposed())
if (!display.readAndDispatch())
display.sleep();
site.deactivateInPlaceClient();
site.dispose();
auto.dispose();
}
private void setOleAutomationPropertiy(OleAutomation auto) ...{
Variant variant = null;
variant = new Variant(0);
int[] ids = null;
ids = auto.getIDsOfNames(new String[] ...{ "ShowCaptioning" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowControls" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowAudioControls" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowDisplay" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowGotoBar" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowPositionControls" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowStatusBar" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowTracker" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "PlayCount" });
auto.setProperty(ids[0], variant);
variant = new Variant(2);
ids = auto.getIDsOfNames(new String[] ...{ "DisplaySize" });
auto.setProperty(ids[0], variant);
}
}
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/** */ /**
*
* @author Benewu(at)gmail.com
* SWT Player
*/
public class SWTVideoPlayer ... {
public static void main(String[] args) ...{
Display display = new Display();
//设置全屏shell
Shell shell = new Shell(display,SWT.ON_TOP | SWT.TOOL);
// Shell shell = new Shell(display); //带title的窗口
shell.setText("SWT Video Player");
shell.setSize(640, 480);
shell.setLayout(new FillLayout());
OleFrame frm = new OleFrame(shell, SWT.NONE);
OleClientSite site = new OleClientSite(frm, SWT.NONE,
"MediaPlayer.MediaPlayer");
OleAutomation auto = new OleAutomation(site);
int[] ids = null;
ids = auto.getIDsOfNames(new String[] ...{ "Open" });
String mediaFilePath = "D:/Program Files/eMule/Incoming/South.Park.S11E05.Fantastic.Easter.Special.DSR.XviD-CRiMSON.avi";
auto.invoke(ids[0], new Variant[] ...{ new Variant(mediaFilePath) });
new SWTVideoPlayer().setOleAutomationPropertiy(auto);
ids = auto.getIDsOfNames(new String[] ...{ "Play" });
auto.invoke(ids[0]);
shell.open();
while (!shell.isDisposed())
if (!display.readAndDispatch())
display.sleep();
site.deactivateInPlaceClient();
site.dispose();
auto.dispose();
}
private void setOleAutomationPropertiy(OleAutomation auto) ...{
Variant variant = null;
variant = new Variant(0);
int[] ids = null;
ids = auto.getIDsOfNames(new String[] ...{ "ShowCaptioning" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowControls" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowAudioControls" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowDisplay" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowGotoBar" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowPositionControls" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowStatusBar" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "ShowTracker" });
auto.setProperty(ids[0], variant);
ids = auto.getIDsOfNames(new String[] ...{ "PlayCount" });
auto.setProperty(ids[0], variant);
variant = new Variant(2);
ids = auto.getIDsOfNames(new String[] ...{ "DisplaySize" });
auto.setProperty(ids[0], variant);
}
}