--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.editors.win32.ole;\r
+\r
+import org.eclipse.swt.ole.win32.OLE;\r
+import org.eclipse.swt.ole.win32.OleAutomation;\r
+import org.eclipse.swt.ole.win32.OleClientSite;\r
+import org.eclipse.swt.ole.win32.OleFrame;\r
+import org.eclipse.swt.ole.win32.Variant;\r
+import org.simantics.editors.win32.OLEEditorInput;\r
+\r
+\r
+/**\r
+ * Windows Media Player utility.\r
+ * \r
+ * Note: there is a bug with WMP11: it launches WMP website when the control is activated.\r
+ * \r
+ * @see http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg20193.html\r
+ * \r
+ * @author MLMARKO\r
+ *\r
+ */\r
+public class WMPController implements OleController {\r
+ \r
+ OleFrame frame;\r
+ OleClientSite site;\r
+ OleAutomation auto;\r
+ \r
+ public WMPController(OleFrame frame, OleClientSite site, OleAutomation auto) {\r
+ this.frame = frame;\r
+ this.site = site;\r
+ this.auto = auto;\r
+ }\r
+ \r
+ public void show(OLEEditorInput input) {\r
+ site.doVerb(OLE.OLEIVERB_SHOW);\r
+ // size must be 240x245 and uiMode full to correctly align the player component with the editor\r
+ frame.setSize(240, 245);\r
+ // WMP11 won't show video, if uimode is not set to none when URL is set\r
+ setUIMode("none");\r
+ setStrechToFit(true);\r
+ \r
+ String url = "file:///"+ input.getFile().getAbsoluteFile();\r
+ url = url.replace('\\', '/');\r
+ System.out.println(url);\r
+ loadMedia(url);\r
+ \r
+ frame.layout();\r
+ // URL has been set, so we can set uimode to full\r
+ setUIMode("full");\r
+ }\r
+ \r
+ public void setUIMode(String mode) {\r
+ int ids[] = auto.getIDsOfNames(new String[] { "uiMode" });\r
+ if (ids != null) {\r
+ auto.setProperty(ids[0], new Variant(mode)); //"none","full"\r
+ }\r
+ }\r
+ \r
+ public void setStrechToFit(boolean fit) {\r
+ int ids[] = auto.getIDsOfNames(new String[] { "stretchToFit" });\r
+ if (ids != null) {\r
+ auto.setProperty(ids[0], new Variant(fit));\r
+ }\r
+ }\r
+ \r
+ public void loadMedia(String url) {\r
+ int[] rgdispid;\r
+ rgdispid = auto.getIDsOfNames(new String[]{"URL"});\r
+ if (rgdispid != null) {\r
+ int dispIdMember = rgdispid[0];\r
+ \r
+ boolean b = auto.setProperty(dispIdMember, new Variant(url));\r
+ System.out.println(b);\r
+ } \r
+ }\r
+ \r
+ public void play() {\r
+ int[] rgdispid = auto.getIDsOfNames(new String[] { "controls" }); //$NON-NLS-1$\r
+ Variant pVarResult = auto.getProperty(rgdispid[0]);\r
+ if (pVarResult == null || pVarResult.getType() == 0)\r
+ return;\r
+ OleAutomation controls = pVarResult.getAutomation();\r
+ rgdispid = controls.getIDsOfNames(new String[] { "play" }); //$NON-NLS-1$\r
+ controls.invoke(rgdispid[0]);\r
+ pVarResult.dispose();\r
+ controls.dispose();\r
+ }\r
+ \r
+ public void stop() {\r
+ int[] rgdispid = auto.getIDsOfNames(new String[] { "controls" }); //$NON-NLS-1$\r
+ Variant pVarResult = auto.getProperty(rgdispid[0]);\r
+ if (pVarResult == null || pVarResult.getType() == 0) return;\r
+ OleAutomation controls = pVarResult.getAutomation();\r
+ rgdispid = controls.getIDsOfNames(new String[]{ "stop" }); //$NON-NLS-1$\r
+ controls.invoke(rgdispid[0]);\r
+ pVarResult.dispose();\r
+ controls.dispose();\r
+ }\r
+ \r
+ public boolean setFullScreen(boolean mode) {\r
+ int[] rgdispid = auto.getIDsOfNames(new String[] { "fullScreen" }); //$NON-NLS-1$\r
+ boolean result = auto.setProperty(rgdispid[0], new Variant(mode));\r
+ return result;\r
+ }\r
+ \r
+ public boolean setWindowlessVideo(boolean mode) {\r
+ int[] rgdispid = auto.getIDsOfNames(new String[] { "windowlessVideo" }); //$NON-NLS-1$\r
+ boolean result = auto.setProperty(rgdispid[0], new Variant(mode));\r
+ return result;\r
+ }\r
+ \r
+ public String getStatus() {\r
+ int[] rgdispid = auto.getIDsOfNames(new String[] { "status" }); //$NON-NLS-1$\r
+ Variant pVarResult = auto.getProperty(rgdispid[0]);\r
+ if (pVarResult == null || pVarResult.getType() != OLE.VT_BSTR)\r
+ return "";\r
+ String result = pVarResult.getString();\r
+ pVarResult.dispose();\r
+ return result;\r
+ }\r
+\r
+}\r