简体   繁体   English

在Mfc中嵌入Window Media Player

[英]Embedding Window Media Player in mfc

I am embedding a window media player activex control in a dialog based mfc application. 我在基于对话框的mfc应用程序中嵌入了窗口媒体播放器activex控件。 Now all play/pause button is getting disabled. 现在,所有播放/暂停按钮都被禁用。 I want to enable them. 我要启用它们。

As I have put put_uiMode(_T("mini")); 正如我所说的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. b的值即将变为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
}

MSDN says : MSDN说

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

This assumes that the player is already properly initialized as ActiveX control. 这假定播放器已经正确初始化为ActiveX控件。 In your code, you simply create a COM object without doing any ActiveX Control initialization. 在您的代码中,您只需创建一个COM对象,而无需进行任何ActiveX控件初始化。 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." ”在各个put_fullScreen调用中,您的hr put_fullScreen应为0xC00D0FD2 NS_E_WMPOCX_NO_ACTIVE_CORE “所请求的方法或属性不可用,因为Windows Media Player ActiveX控件未正确激活。” to indicate the problem. 指出问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM