Microsoft Windows CE 3.0  

Playing the File

Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Playing a file using DirectShow is a three-step process:

  1. Create an instance of the filter graph manager.
  2. Use the filter graph manager to create a filter graph.
  3. Use the filter graph manager to run the filter graph.

    To accomplish this, you need to use two interfaces:

    • IGraphBuilder: Constructs the filter graph.
    • IMediaControl: Handles media streaming in the filter graph.

      The filter graph manager implements both of these interfaces. Here is the basic code, minus some COM details:

      IGraphBuilder *pGraph; IMediaControl
      *pMediaControl; CoCreateInstance(CLSID_FilterGraph, NULL,
      CLSCTX_INPROC, IID_IGraphBuilder, (void **)&pGraph); // Query
      for IMediaControl (not shown) // Filenames on Windows CE start with
      a \\ instead of a drive letter.
      pGraph->RenderFile(L"\\Hello_World.avi", NULL);
      pMediaControl->Run();

      The IGraphBuilder::RenderFilemethod constructs a filter graph that will play the specified file. The first parameter is the file name, represented as a wide character (2-byte) Unicode string. For simplicity, the example program specifies a literal string, rather than have the user select a file name. The "L" prefix converts an ASCII string to a wide character string. The second parameter is reserved and must equal NULL.

      After the filter graph manager has constructed a filter graph, it is ready to begin playback. The IMediaControl::Runmethod switches the graph into running mode. When the application invokes this method, media data begins to move through the filter graph and is rendered as video, audio, or both.

      If this were the last statement in the program, the program would abruptly stop the moment playback began. In a real application, you would wait for an end-of-stream event, a topic discussed in Responding to Events. To keep the example as short as possible, the sample program merely displays a message box, which blocks program execution. Playback continues on a separate thread until the user clicks the OK button. Also, in a real application, you should test the return value of RenderFileto confirm that it created the filter graph successfully. For example, if the specified file does not exist, RenderFilefails and returns the error code VFW_E_NOT_FOUND.



       Last updated on Tuesday, May 18, 2004

      © 2004 Microsoft Corporation. All rights reserved.