Embedding Window Media Player in mfc

2k views Asked by At

I am embedding a window media player activex control in a dialog based mfc application. Now all play/pause button is getting disabled. I want to enable them.

As I have put put_uiMode(_T("mini")); and when writingthese lines

hr = m_spWMPPlayer->put_fullScreen(VARIANT_TRUE)
 hr = m_spWMPPlayer->get_fullScreen(&b); // returned b = VARIANT_FALSE

value of b is coming FALSE.

What could be the error? Any one knows this?

Thank You

BOOL CLuminPlayerDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    CComPtr<IWMPPlayer>         m_spWMPPlayer;
    CComPtr<IWMPRemoteMediaServices> m_spServices;
    CComPtr<IWMPControls>           m_spControls;

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);         // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    // TODO: Add extra initialization here
    HRESULT hr = NULL;
    if(SUCCEEDED(hr))
    {
        hr = CoCreateInstance(__uuidof(WindowsMediaPlayer), 0, CLSCTX_INPROC_SERVER, IID_IOleObject, (void**)&m_spServices);

        if(SUCCEEDED(hr))
        {
            BSTR str = NULL;

            VARIANT_BOOL b ;
            hr = m_spServices->QueryInterface(__uuidof(IWMPPlayer), (void**)&m_spWMPPlayer);
            if(SUCCEEDED(hr))
            {

                hr = m_spWMPPlayer->get_enabled(&b); // returned b= VARIANT_TRUE
                hr = m_spWMPPlayer->get_enableContextMenu(&b); //returned b = VARIANT_TRUE
                hr = m_spWMPPlayer->get_uiMode(&str); // returned str = L"full"
                hr = m_spWMPPlayer->put_uiMode(_T("mini")); //hr = S_OK
                hr = m_spWMPPlayer->get_uiMode(&str); // str = L"mini"
                hr = m_spWMPPlayer->put_fullScreen(VARIANT_TRUE); 
                hr = m_spWMPPlayer->get_fullScreen(&b); // returned b = VARIANT_FALSE
                hr = m_spWMPPlayer->put_URL(_T("C:\\Visual Studio 2012\\Projects\\Lumin-Player\\Debug\\abc.mp4")); //returned hr = S_OK

                hr = m_spServices->QueryInterface(__uuidof(IWMPControls), (void**)&m_spControls); // returned hr = S_OK
                if(SUCCEEDED(hr))
                {
                    hr = m_spControls->play(); //returned hr = S_OK
                }
            }
        }
    }

    return TRUE;  // return TRUE  unless you set the focus to a control
}
1

There are 1 answers

0
Roman Ryltsov On

MSDN says:

For full-screen mode to work properly when embedding the Windows Media Player control, the video display area must have a height and width of at least one pixel. If the BSTR specified in IWMPPlayer::put_uiMode is set to "mini" or "full", the height of the control itself must be 65 pixels or greater to accommodate the video display area in addition to the user interface.

This assumes that the player is already properly initialized as ActiveX control. In your code, you simply create a COM object without doing any ActiveX Control initialization. Presumably the player detects this and reports error.

Your hr in respective put_fullScreen call should have 0xC00D0FD2 NS_E_WMPOCX_NO_ACTIVE_CORE "The requested method or property is not available because the Windows Media Player ActiveX control has not been properly activated." to indicate the problem.