Reading Files with the Asynchronous Reader

[The feature associated with this page, Windows Media Format 11 SDK, is a legacy feature. It has been superseded by Source Reader and Sink Writer. Source Reader and Sink Writer have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Source Reader and Sink Writer instead of Windows Media Format 11 SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The asynchronous reader reads the content from ASF files using multiple threads and asynchronous calls. The features supported by the asynchronous reader make it well suited for applications that render content to end users.

The most basic functionality of the reader object can be broken down into the following steps. In these steps "the application" refers to the program you write using the Windows Media Format SDK.

  1. The application implements the IWMReaderCallback interface to handle messages from the reader. This includes two callback methods: OnStatus, which receives messages relating to the status of various aspects of the reader and OnSample, which receives uncompressed samples from the reader.
  2. The application passes to the reader the name of a file to read. When the reader opens the file, it assigns an output number to each stream. If the file uses mutual exclusion, the reader assigns a single output for all of the mutually exclusive streams.
  3. The application gets information about the configuration of the various outputs from the reader. The information gathered will enable the application to properly render media samples.
  4. The application instructs the reader to begin reading data from the file. The reader begins delivering uncompressed samples to the OnSample callback one at a time in buffers wrapped in buffer objects. The samples delivered by the reader are in presentation-time order. The reader will continue delivering samples until stopped by the application or until the end of the file is reached.
  5. The application is responsible for rendering data after it is delivered by the reader. The Windows Media Format SDK does not provide any rendering routines. Typically, applications will use other SDKs to render data, such as the Microsoft DirectX® SDK, or the multimedia functions of the Microsoft Windows Platform SDK.
  6. When reading is complete, the application instructs the reader to close the file.

These steps are illustrated in the AudioPlayer sample application, among others. For more information, see Sample Applications.

The reader also supports more advanced functionality. The reader enables you to do the following:

  • Pause playback of a file.
  • Retrieve reader performance statistics.
  • Control stream selection for mutually exclusive streams.
  • Manually allocate buffers for output.
  • Provide your own clock.
  • Retrieve the status of file operations (buffering, download, or save).
  • Open a file using the standard COM interface, IStream.
  • Seek to specific points in an ASF file.
  • Read profile data from the header of the file.

The following sections describe the use of the reader object in detail.

Reading ASF Files

Reader Object