-----Original
Message-----
From: Negi, Pramod
Singh
Sent: Monday, August 07,
2006 11:31 AM
To:
platform-swt-dev@xxxxxxxxxxx
Subject: [platform-swt-dev] Problem with
ActiveXControl WMPlayer.ocx
Hello
Today's
Topics:
1. Problem with ActiveX Control
(Pramod)
I am Pramod.
I am facing the problem in embedding Window Media Player
in SWT Application.
In my application I have to create more than one
instances of Media Player to display video, all the video may be same or
different depends on the user.
I have used the Shell as parent on which OleFrame,
OleControlSite, OleAutomation has been added.
Everything is fine but when closing the any one of the
instance it shows that VM crash and all the instances closed
itself.
My code snippet (API) is
here
import org.eclipse.swt.SWT;
import
org.eclipse.swt.SWTError;
import
org.eclipse.swt.graphics.Point;
import
org.eclipse.swt.layout.FormAttachment;
import
org.eclipse.swt.layout.FormData;
import
org.eclipse.swt.layout.FormLayout;
import
org.eclipse.swt.ole.win32.OLE;
import
org.eclipse.swt.ole.win32.OleAutomation;
import
org.eclipse.swt.ole.win32.OleControlSite;
import
org.eclipse.swt.ole.win32.OleFrame;
import
org.eclipse.swt.ole.win32.Variant;
import
org.eclipse.swt.widgets.Composite;
import
org.eclipse.swt.widgets.Label;
/**
* Embeds
the MediaPlayer ActiveX onto a displet.
*/
public class
EmbedActiveXControl
{
private Composite mComposite;
private String mURL;
private OleFrame mOleFrame;
/**
* @param aParent
*
* @param aStyle
*
*/
public EmbedActiveXControl(Composite aParent, int aStyle, String
anURL)
{
mComposite = aParent;
FormLayout formLayout = new FormLayout();
mComposite.setLayout(formLayout);
mURL
= anURL;
addLabel();
mComposite.setEnabled(true);
mComposite.setVisible(true);
addStatusBar();
}
/**
*
* Creates OleFrame that contains the ActiveX
control.
*
*/
public void createVideoContainer (Point aSize, Point
aLocation)
{
mOleFrame = createOleFrame(aSize,
aLocation);
addMediaPlayerControl();
}
// Helper methods
//
===============================================================
private OleFrame createOleFrame (Point aSize, Point
aLocation)
{
OleFrame oleFrame = new OleFrame(mComposite,
SWT.NONE);
oleFrame.setLocation(aLocation);
oleFrame.setSize(aSize);
return oleFrame;
}
/**
*
* Adds the ActiveX control to the OleFrame and makes it
visible.
*
*/
private void addMediaPlayerControl
()
{
OleControlSite controlSite = new OleControlSite(mOleFrame, SWT.BORDER,
"wmplayer.ocx");
controlSite.setSize(mOleFrame.getSize());
try
{
controlSite.doVerb(OLE.OLEIVERB_SHOW);
}
catch(SWTError anError)
{
System.out.println("Unable to Open The Activex
Control");
return;
}
OleAutomation mediaPlayer = new
OleAutomation(controlSite);
mComposite.pack();
setUIMode(mediaPlayer, "none");
loadFile(mediaPlayer, mURL);
}
/**
*
* @param anURL
*
* @return boolean
*
*/
private boolean loadFile (OleAutomation aMediaPlayer, String
anURL)
{
int[] ids = aMediaPlayer.getIDsOfNames(new
String[]{"URL"});
if
(ids != null)
{
Variant theFile = new Variant(anURL);
return aMediaPlayer.setProperty(ids[0],
theFile);
}
return false;
}
private void setUIMode (OleAutomation aMediaPlayer, String
s)
{
int
ids[] = aMediaPlayer.getIDsOfNames(new
String[]{"uiMode"});
if
(ids != null)
{
aMediaPlayer.setProperty(ids[0], new
Variant(s));
}
}
private void addStatusBar ()
{
Label label = new Label(mComposite,
SWT.BORDER);
label.setText("StatusBar");
FormData labelData = new FormData();
labelData.left = new FormAttachment(0);
labelData.right = new FormAttachment(100);
labelData.bottom = new FormAttachment(100);
label.setLayoutData(labelData);
}
private void addLabel ()
{
Label label = new Label(mComposite,
SWT.NONE);
label.setLocation(new Point(10, 10));
label.setText("URL " + mURL);
}
}
The user will create the instance of EmbedActiveXControl first and call the
createVideoContainer() method than.
On closing one of the instances, it shows vm
crash.
Is
it a bug?
Is
there an error in my code?
Please
help me to resolve this problem.