Sign in to follow this  

Hang when looping video in DShow

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.

	//	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);

	InvalidateRect(m_main_hwnd, NULL, false);

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

		m_pMediaSeeking->SetPositions(&pos, AM_SEEKING_AbsolutePositioning, &pos, AM_SEEKING_NoPositioning);
		InvalidateRect(m_main_hwnd, 0, 0);

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

		return false;

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

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

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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this