Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to embed the embed Window Media Player in a dialog in MFC. I am using these steps:

I created one new dialog based application in mfc
Right Click on dialog->Insert ActivexControl->Window Media Player

Now I want to run a video file at run time. For that I am writing some code inside
OnInitDialog()

I am writing this code inside
OnInitDialog()


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

    // 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 = CoCreateInstance(__uuidof(WindowsMediaPlayer), 0, CLSCTX_INPROC_SERVER, IID_IOleObject, (void**)&oleObject);

    IWMPPlayer4* pPlayer = NULL;
    hr = oleObject->QueryInterface(__uuidof(IWMPPlayer4), (void**)&pPlayer);
    pPlayer->put_uiMode(_T("full"));

    IWMPSettings *pSettings=NULL;
    hr = pPlayer->QueryInterface(__uuidof(IWMPSettings), (void **)&pSettings);

    IWMPControls *pControls = NULL;
    hr =    pPlayer->QueryInterface(__uuidof(IWMPControls), (void **)&pControls);
    hr =    pPlayer->put_enabled(VARIANT_TRUE);
    hr =    pPlayer->put_URL(_T("d:\\abcd.mp4"));   
    hr =    pControls->play();
    hr =    pControls->Release();
    hr =    pPlayer->Release();

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


here
oleObject
is of type
IOleObject*


Now I am not able to see the video but I can listen and loose all functionality of window media player like increase or decrease the volume and Play button got disabled. I want to run audio/video files with all functionality of window media player.

I took help from these articles:

http://msdn.microsoft.com/en-us/library/dd564580(VS.85).aspx

Can anyone help me.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900