c++ - 在mfc中嵌入Window Media Player

标签 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
}

最佳答案

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.

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

您在相应 put_fullScreen 调用中的 hr 应该有 0xC00D0FD2 NS_E_WMPOCX_NO_ACTIVE_CORE “请求的方法或属性不可用因为 Windows Media Player ActiveX 控件没有被正确激活。”指出问题。

关于c++ - 在mfc中嵌入Window Media Player,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26987253/

相关文章:

visual-studio - 我可以使用 list 来指定对 COM 服务器的可选依赖项吗?

multithreading - CoInitialize 在 Delphi DataSnap 服务器应用程序中

c# - 在 C# 中使用 IBM 的 PCOMM 的示例代码 o 编写 as400 屏幕截图

C++ MFC 如何使用 GetDlgItem()

c++ - 以编程方式在 MFC 中设置单选按钮状态

允许多个字符的 C++ Char 初始化

c++ - 局部变量在函数中保留值

c++ - 默认的默认构造函数可以抛出吗?

c++ - 无法编译 64 位 Visual Studio 2010 项目

c++ - 将成员函数指针传递给 c 风格的函数