• Advertisement
Sign in to follow this  

Hang when looping video in DShow

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys. I am becoming extremely frustrated as to why I have a full 2 second hang when looping video with DirectShow. The video loops, it just hangs like crazy when resetting the position of the video. As of now, my test program is just checking to see; if HandleEvents() returns true, RestartVideo(). Any tips or problems you point out in my code would be greatly appreciated. Thanks in advance! p.s. The Invalidate() calls in both the PlayVideo() and RestartVideo() functions arent necessary, nor are the Stop() and Run() calls in the RestartVideo() function. Just there for piece of mind, and dont affect the hang. Current applicable functions:
void CDShowWrapper::PlayVideo()
{

	//	Video to be played.
	m_pGraphBuilder->RenderFile(L"Menu.m2v", NULL);

	//	Query for the Interfaces.
	m_pGraphBuilder->QueryInterface(IID_IVideoWindow, (void**)&m_pVideoWindow);
	m_pGraphBuilder->QueryInterface(IID_IMediaEventEx, (void**)&m_pMediaEventEx);
	m_pGraphBuilder->QueryInterface(IID_IMediaControl, (void**)&m_pMediaControl);
	m_pGraphBuilder->QueryInterface(IID_IMediaSeeking, (void**)&m_pMediaSeeking);

	//	Setup the Queried Interfaces.
	m_pVideoWindow->put_Owner((OAHWND)m_main_hwnd);
	m_pVideoWindow->put_Visible(OATRUE);

	//	Give the Video Window some style.
	m_pVideoWindow->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);
	m_pVideoWindow->SetWindowPosition(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);

	//	Setup the Event Handler.
	m_pMediaEventEx->SetNotifyWindow((OAHWND)m_main_hwnd, WM_GRAPHNOTIFY, 0);

	m_pMediaControl->Run();
	InvalidateRect(m_main_hwnd, NULL, false);
}

void CDShowWrapper::RestartVideo()
{
	LONGLONG pos = 0;

	if(m_pMediaSeeking)
	{
		m_pMediaControl->Stop();
		m_pMediaSeeking->SetPositions(&pos, AM_SEEKING_AbsolutePositioning, &pos, AM_SEEKING_NoPositioning);
		m_pMediaControl->Run();
		InvalidateRect(m_main_hwnd, 0, 0);
	}
}

bool CDShowWrapper::HandleEvents()
{
	HRESULT hr = 0;
	long lEvCode, lParam1, lParam2 = 0;

	if(!m_pMediaEventEx)
		return false;

	//	Peek from the Event Queue.
	hr = m_pMediaEventEx->GetEvent(&lEvCode, &lParam1, &lParam2, 0);

	while(SUCCEEDED(hr))
	{
		//	Pop the event from the queue.
		m_pMediaEventEx->FreeEventParams(lEvCode, lParam1, lParam2);

		//	Check the Event Code.
		switch(lEvCode)
		{
			case EC_COMPLETE:
				return true;
				break;
		}
		//	Peek for another event.
		hr = m_pMediaEventEx->GetEvent(&lEvCode, &lParam1, &lParam2, 0);
	}
	return false;
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement