]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.editors.win32/src/org/simantics/editors/win32/ole/WMPController.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.editors.win32 / src / org / simantics / editors / win32 / ole / WMPController.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.editors.win32.ole;
13
14 import org.eclipse.swt.ole.win32.OLE;
15 import org.eclipse.swt.ole.win32.OleAutomation;
16 import org.eclipse.swt.ole.win32.OleClientSite;
17 import org.eclipse.swt.ole.win32.OleFrame;
18 import org.eclipse.swt.ole.win32.Variant;
19 import org.simantics.editors.win32.OLEEditorInput;
20
21
22 /**
23  * Windows Media Player utility.
24  * 
25  * Note: there is a bug with WMP11: it launches WMP website when the control is activated.
26  * 
27  * @see http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg20193.html
28  * 
29  * @author MLMARKO
30  *
31  */
32 public class WMPController implements OleController {
33         
34         OleFrame frame;
35         OleClientSite site;
36         OleAutomation auto;
37         
38         public WMPController(OleFrame frame, OleClientSite site, OleAutomation auto) {
39                 this.frame = frame;
40                 this.site = site;
41                 this.auto = auto;
42         }
43         
44         public void show(OLEEditorInput input) {
45                 site.doVerb(OLE.OLEIVERB_SHOW);
46                 // size must be 240x245 and uiMode full to correctly align the player component with the editor
47                 frame.setSize(240, 245);
48                 // WMP11 won't show video, if uimode is not set to none when URL is set
49                 setUIMode("none");
50         setStrechToFit(true);
51         
52         String url = "file:///"+ input.getFile().getAbsoluteFile();
53                 url = url.replace('\\', '/');
54                 System.out.println(url);
55                 loadMedia(url);
56         
57                 frame.layout();
58                 // URL has been set, so we can set uimode to full
59                 setUIMode("full");
60         }
61         
62         public void setUIMode(String mode) {
63                 int ids[] = auto.getIDsOfNames(new String[] { "uiMode" });
64         if (ids != null) {
65             auto.setProperty(ids[0], new Variant(mode)); //"none","full"
66         }
67         }
68         
69         public void setStrechToFit(boolean fit) {
70                 int ids[] = auto.getIDsOfNames(new String[] { "stretchToFit" });
71         if (ids != null) {
72             auto.setProperty(ids[0], new Variant(fit));
73         }
74         }
75         
76         public void loadMedia(String url) {
77                 int[] rgdispid;
78                 rgdispid = auto.getIDsOfNames(new String[]{"URL"});
79                 if (rgdispid != null) {
80                         int dispIdMember = rgdispid[0];
81                         
82                         boolean b = auto.setProperty(dispIdMember, new Variant(url));
83                         System.out.println(b);
84                 }       
85         }
86         
87         public void play() {
88                 int[] rgdispid = auto.getIDsOfNames(new String[] { "controls" }); //$NON-NLS-1$
89                 Variant pVarResult = auto.getProperty(rgdispid[0]);
90                 if (pVarResult == null || pVarResult.getType() == 0)
91                         return;
92                 OleAutomation controls = pVarResult.getAutomation();
93                 rgdispid = controls.getIDsOfNames(new String[] { "play" }); //$NON-NLS-1$
94                 controls.invoke(rgdispid[0]);
95                 pVarResult.dispose();
96                 controls.dispose();
97         }
98         
99         public void stop() {
100                 int[] rgdispid = auto.getIDsOfNames(new String[] { "controls" }); //$NON-NLS-1$
101                 Variant pVarResult = auto.getProperty(rgdispid[0]);
102                 if (pVarResult == null || pVarResult.getType() == 0) return;
103                 OleAutomation controls = pVarResult.getAutomation();
104                 rgdispid = controls.getIDsOfNames(new String[]{ "stop" }); //$NON-NLS-1$
105                 controls.invoke(rgdispid[0]);
106                 pVarResult.dispose();
107                 controls.dispose();
108     }
109         
110         public boolean setFullScreen(boolean mode) {
111                 int[] rgdispid = auto.getIDsOfNames(new String[] { "fullScreen" }); //$NON-NLS-1$
112                 boolean result = auto.setProperty(rgdispid[0], new Variant(mode));
113                 return result;
114         }
115         
116         public boolean setWindowlessVideo(boolean mode) {
117                 int[] rgdispid = auto.getIDsOfNames(new String[] { "windowlessVideo" }); //$NON-NLS-1$
118                 boolean result = auto.setProperty(rgdispid[0], new Variant(mode));
119                 return result;
120         }
121         
122         public String getStatus() {
123                 int[] rgdispid = auto.getIDsOfNames(new String[] { "status" }); //$NON-NLS-1$
124                 Variant pVarResult = auto.getProperty(rgdispid[0]);
125                 if (pVarResult == null || pVarResult.getType() != OLE.VT_BSTR)
126                         return "";
127                 String result = pVarResult.getString();
128                 pVarResult.dispose();
129                 return result;
130         }
131
132 }