1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.editors.win32.ole;
\r
14 import org.eclipse.swt.ole.win32.OLE;
\r
15 import org.eclipse.swt.ole.win32.OleAutomation;
\r
16 import org.eclipse.swt.ole.win32.OleClientSite;
\r
17 import org.eclipse.swt.ole.win32.OleFrame;
\r
18 import org.eclipse.swt.ole.win32.Variant;
\r
19 import org.simantics.editors.win32.OLEEditorInput;
\r
23 * Windows Media Player utility.
\r
25 * Note: there is a bug with WMP11: it launches WMP website when the control is activated.
\r
27 * @see http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg20193.html
\r
32 public class WMPController implements OleController {
\r
38 public WMPController(OleFrame frame, OleClientSite site, OleAutomation auto) {
\r
44 public void show(OLEEditorInput input) {
\r
45 site.doVerb(OLE.OLEIVERB_SHOW);
\r
46 // size must be 240x245 and uiMode full to correctly align the player component with the editor
\r
47 frame.setSize(240, 245);
\r
48 // WMP11 won't show video, if uimode is not set to none when URL is set
\r
50 setStrechToFit(true);
\r
52 String url = "file:///"+ input.getFile().getAbsoluteFile();
\r
53 url = url.replace('\\', '/');
\r
54 System.out.println(url);
\r
58 // URL has been set, so we can set uimode to full
\r
62 public void setUIMode(String mode) {
\r
63 int ids[] = auto.getIDsOfNames(new String[] { "uiMode" });
\r
65 auto.setProperty(ids[0], new Variant(mode)); //"none","full"
\r
69 public void setStrechToFit(boolean fit) {
\r
70 int ids[] = auto.getIDsOfNames(new String[] { "stretchToFit" });
\r
72 auto.setProperty(ids[0], new Variant(fit));
\r
76 public void loadMedia(String url) {
\r
78 rgdispid = auto.getIDsOfNames(new String[]{"URL"});
\r
79 if (rgdispid != null) {
\r
80 int dispIdMember = rgdispid[0];
\r
82 boolean b = auto.setProperty(dispIdMember, new Variant(url));
\r
83 System.out.println(b);
\r
87 public void play() {
\r
88 int[] rgdispid = auto.getIDsOfNames(new String[] { "controls" }); //$NON-NLS-1$
\r
89 Variant pVarResult = auto.getProperty(rgdispid[0]);
\r
90 if (pVarResult == null || pVarResult.getType() == 0)
\r
92 OleAutomation controls = pVarResult.getAutomation();
\r
93 rgdispid = controls.getIDsOfNames(new String[] { "play" }); //$NON-NLS-1$
\r
94 controls.invoke(rgdispid[0]);
\r
95 pVarResult.dispose();
\r
99 public void stop() {
\r
100 int[] rgdispid = auto.getIDsOfNames(new String[] { "controls" }); //$NON-NLS-1$
\r
101 Variant pVarResult = auto.getProperty(rgdispid[0]);
\r
102 if (pVarResult == null || pVarResult.getType() == 0) return;
\r
103 OleAutomation controls = pVarResult.getAutomation();
\r
104 rgdispid = controls.getIDsOfNames(new String[]{ "stop" }); //$NON-NLS-1$
\r
105 controls.invoke(rgdispid[0]);
\r
106 pVarResult.dispose();
\r
107 controls.dispose();
\r
110 public boolean setFullScreen(boolean mode) {
\r
111 int[] rgdispid = auto.getIDsOfNames(new String[] { "fullScreen" }); //$NON-NLS-1$
\r
112 boolean result = auto.setProperty(rgdispid[0], new Variant(mode));
\r
116 public boolean setWindowlessVideo(boolean mode) {
\r
117 int[] rgdispid = auto.getIDsOfNames(new String[] { "windowlessVideo" }); //$NON-NLS-1$
\r
118 boolean result = auto.setProperty(rgdispid[0], new Variant(mode));
\r
122 public String getStatus() {
\r
123 int[] rgdispid = auto.getIDsOfNames(new String[] { "status" }); //$NON-NLS-1$
\r
124 Variant pVarResult = auto.getProperty(rgdispid[0]);
\r
125 if (pVarResult == null || pVarResult.getType() != OLE.VT_BSTR)
\r
127 String result = pVarResult.getString();
\r
128 pVarResult.dispose();
\r