Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Am Playing the video by creating the filter graph using directshow in MFC. If i press the control which is in the parent dialog box i need to play the video in parent dialog box as well as child dialog box. The video was played in parent dialog box, to play as well as in child window what i have to do.

Here is my code:

C++
// playbackControls1Dlg.cpp : implementation file
// CplaybackControls1Dlg dialog
CplaybackControls1Dlg::CplaybackControls1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CplaybackControls1Dlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	z=new CZoom;
}
// CplaybackControls1Dlg message handlers
BOOL CplaybackControls1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	// Add "About..." menu item to system menu.
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
	// 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
        // Create the filter graph manager and query for interfaces.
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
                        IID_IGraphBuilder, (void **)&pGraph);
    if (FAILED(hr))
    {
        MessageBox(L"ERROR - Could not create the Filter Graph Manager.");
        return FALSE;
    }
    hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
    hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
    IMediaEventEx *g_pEvent = NULL;
    pGraph->QueryInterface(IID_IMediaEventEx, (void **)&pEvent);
    hr = InitWindowlessVMR(AfxGetMainWnd()->m_hWnd, pGraph, &pWc);
    hr=pGraph->RenderFile(L"C:\\Documents and Settings\\BTC\\Desktop\\hai.mp4", NULL);
    VideoSize();	
    return TRUE;  // return TRUE  unless you set the focus to a control
}
void CplaybackControls1Dlg::OnBnClickedPlayButton()
{
	// TODO: Add your control notification handler code here
	
	hr = pEvent->SetNotifyWindow((OAHWND)AfxGetMainWnd()->m_hWnd, WM_GRAPHNOTIFY, 0);

	if (SUCCEEDED(hr))
    {
        // Run the graph.
        hr = pControl->Run();
	z->ShowWindow(SW_SHOW);
    }
}
HRESULT CplaybackControls1Dlg::InitWindowlessVMR( 
    HWND hwndApp,                  // Window to hold the video. 
    IGraphBuilder* pGraph,         // Pointer to the Filter Graph Manager. 
    IVMRWindowlessControl** ppWc   // Receives a pointer to the VMR.
    ) 
{ 
    if (!pGraph || !ppWc) 
    {
        return E_POINTER;
    }
    IBaseFilter* pVmr = NULL; 
    IVMRWindowlessControl* pWc = NULL; 
    // Create the VMR. 
    HRESULT hr = CoCreateInstance(CLSID_VideoMixingRenderer, NULL, 
        CLSCTX_INPROC, IID_IBaseFilter, (void**)&pVmr); 
    if (FAILED(hr))
    {
        return hr;
    }   
    // Add the VMR to the filter graph.
    hr = pGraph->AddFilter(pVmr, L"Video Mixing Renderer"); 
    if (FAILED(hr)) 
    {
        pVmr->Release();
        return hr;
    }
    // Set the rendering mode.  
    IVMRFilterConfig* pConfig; 
    hr = pVmr->QueryInterface(IID_IVMRFilterConfig, (void**)&pConfig); 
    if (SUCCEEDED(hr)) 
    { 
        hr = pConfig->SetRenderingMode(VMRMode_Windowless); 
        pConfig->Release(); 
    }
    if (SUCCEEDED(hr))
    {
        // Set the window. 
        hr = pVmr->QueryInterface(IID_IVMRWindowlessControl, (void**)&pWc);
        if( SUCCEEDED(hr)) 
        { 
            hr = pWc->SetVideoClippingWindow(hwndApp); 
            if (SUCCEEDED(hr))
            {
                *ppWc = pWc; // Return this as an AddRef'd pointer. 
            }
            else
            {
                // An error occurred, so release the interface.
                pWc->Release();
            }
        } 
    } 
    pVmr->Release(); 
    return hr; 
} 
int CplaybackControls1Dlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here
	z->Create(IDD_DIALOG1,this);
	z->ShowWindow(FALSE);
	return 0;
}
LRESULT CplaybackControls1Dlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	// TODO: Add your specialized code here and/or call the base class
switch(message)
{
case WM_GRAPHNOTIFY:
	HandleGraphEvent();
    break;
case WM_CLOSE:
	CleanUp();
	break;
}
	return CDialog::WindowProc(message, wParam, lParam);
}
void CplaybackControls1Dlg::HandleGraphEvent()
{
    // Disregard if we don't have an IMediaEventEx pointer.
    if (pEvent == NULL)
    {
        return;
    }
    // Get all the events
    long evCode;
    LONG_PTR param1, param2;
    while (SUCCEEDED(pEvent->GetEvent(&evCode, ¶m1, ¶m2, 0)))
    {
        pEvent->FreeEventParams(evCode, param1, param2);
        switch (evCode)
        {
        case EC_COMPLETE:  // Fall through.
        case EC_USERABORT: // Fall through.
        case EC_ERRORABORT:
	pControl->Stop();
        pEvent->SetNotifyWindow(NULL, 0, 0);
        return;
        }
    } 
}
void CplaybackControls1Dlg::CleanUp()
{
	pWc->Release();
        pControl->Release();
        pGraph->Release();
	pEvent->Release();
}
void CplaybackControls1Dlg::VideoSize()
{
	long lWidth, lHeight; 
	hr = pWc->GetNativeVideoSize(&lWidth, &lHeight, NULL, NULL); 
	if (SUCCEEDED(hr))
	{
		RECT rcSrc, rcDest; 
		// Set the source rectangle.
		SetRect(&rcSrc, 0, 0, lWidth, lHeight);
		// Get the window client area.
		GetClientRect(&rcDest); 
		// Set the destination rectangle.
		SetRect(&rcDest, 0, 40, rcDest.right, rcDest.bottom); 
	    	// Set the video position.
		hr = pWc->SetVideoPosition(&rcSrc, &rcDest); 
	}
	
}


CZoom is the child window.
This code is for playing the video in the parent window. What changes i have to make to play the video in the child.

Thank You in advance,
Posted
Updated 8-Jan-13 3:41am
v6

By making a method like play and add axwindowsmediaplayer control in both the window (Parent and child ) and on load call the method for playing that video..
 
Share this answer
 
Comments
J.Surjith Kumar 8-Jan-13 7:31am    
Am doing it in MFC.
[no name] 8-Jan-13 7:35am    
then what happened... which type of exception is genrated
JackDingler 8-Jan-13 15:16pm    
That should work.
I assume you need the windows to be synchronized? You can't just start playback in one thread and then playback in another window in a second thread thread?

I don't know exactly how to do it, but I would approach it in the following manner. there may be an easier way to do it...

1. Create a class to describe the playback characteristics for a window. I'll refer to this as CVideoPlaybackSetting. It will contain at least the following members.
a. CWnd m_hWnd; // Handle for the window, you may need a context of some type here.
b. CRect m_VideoRect; // Defines the rectangle in the window that the video will be displayed in.

2. Create a video player class to manage the video playback. For now I'll refer to this as CVideoPlayer. It will contain an array of CVideoPlaybackSetting. It will have an interface hook to catch each frame during playback and render to each window in the list.

3. Assign any window you want video play back to occur in, to CVideoPlayer.

4. Start playback.

Note that you'll likely have to create a render surface of some kind for the playback and hook into notifications as the frames are rendered to it. This gets quite a bit more complicated, then just telling the DX engine to play the movie.
 
Share this answer
 

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