Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Am trying to play the video with some of the basic controls included like play, pause and stop. If i use this code
C++
if (SUCCEEDED(hr))
  {
      // Run the graph.
      hr = pControl->Run();
      if (SUCCEEDED(hr))
      {
          // Wait for completion.
          long evCode;
          pEvent->WaitForCompletion(INFINITE, &evCode);

          // Note: Do not use INFINITE in a real application, because it
          // can block indefinitely.
      }
  }

It waits for the video to complete so i cant pause the playing video.
so i used (responding to event)
C++
#define WM_GRAPHNOTIFY  WM_APP + 1


C#
IMediaEventEx *g_pEvent = NULL;
g_pGraph->QueryInterface(IID_IMediaEventEx, (void **)&g_pEvent);
g_pEvent->SetNotifyWindow((OAHWND)g_hwnd, WM_GRAPHNOTIFY, 0);


C#
case WM_GRAPHNOTIFY:
    HandleGraphEvent();
    break;


C#
void HandleGraphEvent()
{
    // Disregard if we don't have an IMediaEventEx pointer.
    if (g_pEvent == NULL)
    {
        return;
    }
    // Get all the events
    long evCode;
    LONG_PTR param1, param2;
    HRESULT hr;
    while (SUCCEEDED(g_pEvent->GetEvent(&evCode, ¶m1, ¶m2, 0)))
    {
        g_pEvent->FreeEventParams(evCode, param1, param2);
        switch (evCode)
        {
        case EC_COMPLETE:  // Fall through.
        case EC_USERABORT: // Fall through.
        case EC_ERRORABORT:
            CleanUp();
            PostQuitMessage(0);
            return;
        }
    } 
}


C#
// Disable event notification before releasing the graph.
g_pEvent->SetNotifyWindow(NULL, 0, 0);
g_pEvent->Release();
g_pEvent = NULL;


I commented the waitforcompletion method, it executed sucessfully but the video was not played.

Your suggestions are welcome.
Posted
Comments
J.Surjith Kumar 2-Jan-13 6:02am    
The code which is above is the right code. I found out small mistake in my code and now it works as i expected.

1 solution

The code which i given above (Responding to event) is works well now.
 
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