Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Problem with WMPlayer.OCX

I am facing the same old problem and need some workaround.
 
Can anyone reply?
 
My code snippet is attached.
 
 
 
 
With Best Regards,
Saurav
 
 

[news.eclipse.platform.swt] WMPlayer.OCX (Windows Media Player) trouble

  • From: Philip Mayer <news@xxxxxxxxxx>
  • Date: Wed, 08 Jun 2005 11:01:49 +0200
  • Newsgroups: eclipse.platform.swt
  • Organization: EclipseCorner
  • User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
 
Hello everyone,


This has been in this group before, but I didn't really find a solution for it. The problem is as follows:

I am trying to use the Windows Media Player (v.10), WMPlayer.OCX, to display video inside an SWT frame. I have sucessfully activated the control and played back some video (Eclipse3.1RC1).

The control, however, cannot be activated using OLE.OLEIVERB_INPLACEACTIVATE (results in a VM crash; there is a bug report on this), but only using OLE.OLEIVERB_SHOW. I SUSPECT that all the following problems are because of this (correct?).

So, when using OLEIVERB_SHOW, it is VERY difficult to set the sizes of the OleFrame and the OleControlSite to the right values in order to display the whole video picture (and only the picture) inside the frame. There are really weird things going on there; mostly, the video is displayed only partly and in strange places inside the black media player area (right click to invoke the media player context menu is possible everwhere). I have found the size (300/206) to be working for me - but only this size, which really is not a solution.

If I use FillLayout or any other layout which allows me to resize the control, the video gets only partly displayed. I tried setting the control's size via listeners, but this doesn't work.

Attached is some code which shows how the WMPlayer tries to play back the video somewhere inside the frame.

Any ideas? :) Thanks !! :)

 

-phil

 

---
public class Snippet3
{
    private OleAutomation player;

 

    public Snippet3()
    {
        final Display display = new Display();
        Shell shell = new Shell(display);
        Composite c1 = new Composite(shell,SWT.NONE);
        shell.setLayout(new FillLayout());
        c1.setLayout(new FillLayout());
        OleControlSite controlSite;


try
{
OleFrame frame = new OleFrame(c1,SWT.NONE);
controlSite = new OleControlSite(frame,SWT.NONE,"WMPlayer.OCX");
controlSite.doVerb(OLE.OLEIVERB_SHOW);
}
catch (SWTError e)
{
System.out.println("Unable to open activeX control");
return;
}
player = new OleAutomation(controlSite);

        c1.setFocus(); // prevents vm from crashing on shutdown.

 

        shell.pack();
        shell.open();

 

        setUIMode("none"); // does not display anything without this line.
        loadFile("c:/windows/clock.avi");

 

        while ( !shell.isDisposed())
        {
            if ( !display.readAndDispatch())
                display.sleep();
        }

 

        player.dispose();
        display.dispose();
    }

 

    public boolean loadFile(String URL) {
        int[] ids = player.getIDsOfNames(new String[] { "URL" });
        if (ids != null) {
            Variant theFile = new Variant(URL);
            return player.setProperty(ids[0], theFile);
        }
        return false;
    }

 

    private void setUIMode(String s) {
        int ids[] = player.getIDsOfNames(new String[] { "uiMode" });
        if (ids != null) {
            player.setProperty(ids[0], new Variant(s));
        }
    }

 

    public static void main(String[] args) {
        new Snippet3();
    }
}

 

 

Saurav Kumar

Software Development Engineer

Barco | Control Rooms

A-5, Sector-5

Noida, India

 

Tel       +91 120 2421651- 60 Ext. 241

Fax      +91 120 2421691

 

http://www.barcocontrolrooms.com

 

--- Begin Message ---
Title: Message

 

 

-----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.

 

 

 


--- End Message ---

Back to the top