Connecting PB to Windows Media Player OLE Control

Posted on 2006-05-18
Last Modified: 2013-12-26
I have a window which has an OLE Control which is the Windows Media Player Active X control. But when I type in 'player.controls.stop()' for example, it will not compile as it says the player object does not exist. How can I instantiate the com object properly so that I can connect to the server and call the wmp com functions.
Question by:Omnipower
    LVL 8

    Accepted Solution

    Function Boolean mciGetErrorStringA(long dwError, ref string lpstrbuffer, int wlength)LIBRARY   "WINMM.DLL"
    FUNCTION boolean sndPlaySoundA(string wavfile, uint flag) LIBRARY "WINMM.DLL"
    FUNCTION uint waveOutGetNumDevs() LIBRARY "WINMM.DLL"
    FUNCTION Long mciSendStringA(string lpstrCommand,  ref string lpstrRtnstring, long wRtnlength, long hCallBack) LIBRARY   "WINMM.DLL"

    string s_errortext
    string filename
    filename = ""
    mciSendStringA ("open "+Filename,s_errortext, 127,0)
    mciSendStringA ("Window " +filename+" Handle "+string(handle(dw_3))+" wait",s_errortext,127, 0)
    mciSendStringA ("Put "+filename+"Destination",s_errortext, 127, 0)
    mciSendStringA ("Set "+filename+" time format frames", s_errortext,127, 0)
    mciSendStringA ("Seek "+filename + " to 1",s_errortext,127,0)
    mciSendStringA ("Play "+filename, s_errortext,127, 0)
    LVL 5

    Assisted Solution

    Hi Omnipower,

    To access the properties of your player you need to call them from OBJECT property of your OLEControl.

    So for:  player.controls.stop()
    Use :    ole_1.object.controls.stop()

    Here it sample code that:

    1. activate OLEControl
    2. Display WMP Version in a messagebox
    3. Set a video file to be played
    4. Play video
    5. Display a Messagebox with the name of the file being played, when you close this messagebox video is Stoped

    You need:

    A window containing an OLEControl OLE_wmp : Object type Windows Media Player, Unchecked "Display as Icon"
    and a CommandButton cb_1

    // Click event on cb_1
    String ls


    ls = ole_wmp.object.versionInfo

    MessageBox("Version", ls)

    ole_wmp.object.URL = "C:\\videos\\BerXpert.wmv"

    ls = ole_wmp.object.URL
    MessageBox("URL", ls )


    // ... End

    I hope it helps,


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
    Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now