在mfc中嵌入Window Media Player

时间:2014-11-18 05:30:28

标签: c++ com mfc activex windows-media-player

我在基于对话框的mfc应用程序中嵌入了一个窗口媒体播放器activex控件。现在所有播放/暂停按钮都被禁用。我想启用它们。

正如我提出put_uiMode(_T("mini")); 当写这些行时

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

b的值变为FALSE。

可能是什么错误?谁知道这个?

谢谢

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 个答案:

答案 0 :(得分:1)

MSDN says

  

要使全屏模式在嵌入Windows Media Player控件时正常工作,视频显示区域的高度和宽度必须至少为一个像素。如果IWMPPlayer :: put_uiMode中指定的BSTR设置为“mini”或“full”,则控件本身的高度必须为65像素或更大,以适应除用户界面之外的视频显示区域。

这假定播放器已正确初始化为ActiveX控件。在您的代码中,您只需创建一个COM对象而无需进行任何ActiveX控件初始化。据推测,玩家会检测到此情况并报告错误。

hr各个put_fullScreen来电中的0xC00D0FD2NS_E_WMPOCX_NO_ACTIVE_CORE {{1}}“请求的方法或属性不可用,因为Windows Media Player ActiveX控件尚未正确激活“。表明问题。