Partager via


Introducing MFPlay

MFPlay is a new high-level playback API for Media Foundation.

Previously, to play a file in Media Foundation, the application had to:

  • Use the source resolver to create a media source.
  • Enumerate the streams and find the media types (audio or video).
  • Construct a partial topology, connecting the streams to the right renderers.
  • Set the topology on the media session.

With MFPlay, the equivalent steps are just one line of code:

 const WCHAR *sURL = L"C:\\Users\\Public\\Videos\\example.wmv";

hr = MFPCreateMediaPlayer(
    sURL,
    TRUE,   // Start playback automatically?
    0,      // Flags.
    NULL,   // Callback pointer.
    hwnd,
    &g_pPlayer
    );

MFPlay also uses a much simpler event mechanism than the media session. The media session requires asynchronous calls to BeginGetEvent/EndGetEvent, and the event callback is invoked from a separate workqueue thread. MFPlay uses a single callback method that passes an event structure:

 STDMETHODIMP MediaPlayerCallback::OnMediaPlayerEvent(
    MFP_EVENT_HEADER *pEventHeader
    )
{
    switch (pEventHeader->eEventType)
    {
    case MFP_EVENT_TYPE_PLAY:
        OnPlay(MFP_GET_PLAY_EVENT(pEventHeader));
        break;

    // Other event types (not shown).

    }
}

By default, the event callback is invoked on your application's WndProc thread, so you can treat MFPlay events much like window messages.

You can read more about MFPlay here:

There is also an MFPlay sample in the Windows 7 BETA SDK, located under Samples\Multimedia\MediaFoundation\SimplePlay.

Please remember that everything new in the SDK is beta and subject to change.

- Mike