Example #1
1
void playNormalVideo()
{
	IGraphBuilder *pGraphBuilder;
	IMediaControl *pMediaControl;
	IMediaEvent *pMediaEvent;
	long eventCode;

	CoInitialize(NULL);

	CoCreateInstance(CLSID_FilterGraph,
		NULL,
		CLSCTX_INPROC,
		IID_IGraphBuilder,
		(LPVOID *)&pGraphBuilder);

	pGraphBuilder->QueryInterface(IID_IMediaControl,
		(LPVOID *)&pMediaControl);

	pGraphBuilder->QueryInterface(IID_IMediaEvent,
		(LPVOID *)&pMediaEvent);

	pMediaControl->RenderFile(L"Rscreen_shortFinger.avi");

	pMediaControl->Run();

	FILTER_STATE fs;
	HRESULT hr = pMediaControl->GetState(100, (OAFilterState*)&fs);

	// The first argument is timeout value.
	// If you change the "-1" part into "2",
	// WaitForCompletion will timeout after 2 seconds.
	pMediaEvent->WaitForCompletion(-1, &eventCode);
	switch (eventCode) {
	 case 0:
		 printf("timeout\n");
		 break;
	 case EC_COMPLETE:
		 printf("complete\n");
		 break;
	 case EC_ERRORABORT:
		 printf("errorabort\n");
		 break;
	 case EC_USERABORT:
		 printf("userabort\n");
		 break;
	}

	hr = pMediaControl->GetState(100, (OAFilterState*)&fs);
	pMediaControl->Run();
	hr = pMediaControl->GetState(100, (OAFilterState*)&fs);
	pMediaEvent->WaitForCompletion(-1, &eventCode);

	pMediaControl->Release();
	pGraphBuilder->Release();
	CoUninitialize();
}
Example #2
0
//
//  Toggle the pause state for the media player.  Returns true if the media player pauses, false if it runs.
//
bool CMediaPlayer::TogglePauseState()
{
    bool isPaused = false;
    IMediaControl *mediaControl;

    HRESULT hr = _GraphBuilder->QueryInterface(IID_PPV_ARGS(&mediaControl));
    if (SUCCEEDED(hr))
    {
        OAFilterState filterState;

        hr = mediaControl->GetState(INFINITE, &filterState);
        if (SUCCEEDED(hr))
        {
            if (filterState == State_Running)
            {
                mediaControl->Pause();
                isPaused = true;
            }
            else if (filterState == State_Paused)
            {
                mediaControl->Run();
                isPaused = false;
            }
        }
        mediaControl->Release();
    }
    return isPaused;
}
Example #3
0
void PlaybackControls::PlayPause()
{
	IMediaControl *pControl = NULL;
	FILTER_STATE fs;
	HRESULT hr;
	
	if (mpGraph)
	{
		hr = mpGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
		pControl->GetState(50, (OAFilterState*)&fs);

		if (fs == State_Running)
			pControl->Pause();
		else
			pControl->Run();

		pControl->Release();
	}
}
bool DirectShowVideoWrapper::isPaused(void) const
{
    if(isInitialized())
    {
		HRESULT hr;

		IMediaControl* mediaControl;
		hr = _pGraphBuilder->QueryInterface(IID_IMediaControl,(void**)&mediaControl);

		OAFilterState GraphState;
		if (SUCCEEDED(mediaControl->GetState(0.1f, &GraphState)))
        {
			return GraphState == State_Paused;
		}
        else
        {
			return false;
		}
    }
    return false;
}