locked
Media Player Control Pointer RRS feed

  • Question

  • I have an ActiveX Windows Media Player plugin in a MFC VC++ application. I am using Visual Studio 2013. I want to enable a movie to play when it is opened. My code to create the ActiveX control and play a move works great, but at this point, I have to click the play button to get it started instead of it starting when opened.

    I found the play() method of the IWMPControls interface here:

    http://msdn.microsoft.com/en-us/library/windows/desktop/dd563179%28v=vs.85%29.aspx

    but I can't figure out how to initialize a pointer to this method. The documentation says to "retrieve a pointer to an IWMPControls interface with the following method" which is get_controls(). But I can't get set up properly to run that method.

    The bottom-line code to get this going is below. What is amazing is that even though I get the debug error, and the app quits running when the movie ends, this code actually does start the movie player without me having to click the play button. If I comment out the final line: m_spWMPController->play(); I can manually play the movie without difficulty.

    So just to reiterate, I want my movie to start when opened. Help would be appreciated.

    HRESULT  hr;
    CAxWindow  *m_pwndView;  // ActiveX host window class.
    CComPtr<IWMPPlayer>  m_spWMPPlayer;  // Smart pointer to IWMPPlayer interface.
    CComPtr<IAxWinHostWindow>  spHost;
    CString TempString;
    CComBSTR bstrString;
    CComPtr<IWMPControls> m_spWMPController;
    
    m_pwndView = new CAxWindow;
    m_pwndView->Create(m_hWnd, Area, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
    hr = m_pwndView->QueryHost(&spHost);
    hr = spHost->CreateControl(CComBSTR(_T("{6BF52A52-394A-11d3-B153-00C04F79FAA6}")), m_pwndView->m_hWnd, 0);
    hr = m_pwndView->QueryControl(&m_spWMPPlayer);
    bstrString = movie.AllocSysString();
    hr = m_spWMPPlayer->put_URL(bstrString);
    ::SysFreeString(bstrString);
    //??????hr = get_controls(&m_spWMPController); How to initialize the m_spWMPController ????
    m_spWMPController->play(); //gives a null pointer debug assertion (but the player does start!)

    Tuesday, May 6, 2014 4:15 PM

Answers

All replies

  • It sounds like IWMPSettings::put_autoStart can do.


    Visual C++ MVP

    Tuesday, May 6, 2014 4:28 PM
  • Yes, thank you very much, I thought of the auto_Start function as well, but there are two problems with that. First, I haven't been able to figure out how to call that method properly either, and second, I also need to be able to call the stop() method just like the play() method, so if auto_Start worked, I would still be back here looking for how to get a pointer to the controls so I could run stop().
    Wednesday, May 7, 2014 8:03 PM