Using the Source Resolver

The source resolver takes a URL or byte stream and creates the appropriate media source for that content. To create the source resolver, call MFCreateSourceResolver. This function returns an IMFSourceResolver interface pointer.

The source resolver has both synchronous and asynchronous methods. If you are using the source resolver from your main application thread, the asynchronous methods will make your user interface more responsive. The synchronous methods can block for a noticeable amount of time, particularly if the source resolver must open a network resource.

The synchronous methods are:

The asynchronous methods are:

For the asynchronous methods, each method has a corresponding End... method to complete the asynchronous request, and a Cancel... method to cancel a pending request. For more information about asynchronous methods in Media Foundation, see Asynchronous Callback Methods.

The following code example creates a media source from a URL. This example uses the synchronous method.

//  Create a media source from a URL.
HRESULT CreateMediaSource(PCWSTR sURL, IMFMediaSource **ppSource)

    IMFSourceResolver* pSourceResolver = NULL;
    IUnknown* pSource = NULL;

    // Create the source resolver.
    HRESULT hr = MFCreateSourceResolver(&pSourceResolver);
    if (FAILED(hr))
        goto done;

    // Use the source resolver to create the media source.

    // Note: For simplicity this sample uses the synchronous method to create 
    // the media source. However, creating a media source can take a noticeable
    // amount of time, especially for a network source. For a more responsive 
    // UI, use the asynchronous BeginCreateObjectFromURL method.

    hr = pSourceResolver->CreateObjectFromURL(
        sURL,                       // URL of the source.
        MF_RESOLUTION_MEDIASOURCE,  // Create a source object.
        NULL,                       // Optional property store.
        &ObjectType,        // Receives the created object type. 
        &pSource            // Receives a pointer to the media source.
    if (FAILED(hr))
        goto done;

    // Get the IMFMediaSource interface from the media source.
    hr = pSource->QueryInterface(IID_PPV_ARGS(ppSource));

    return hr;

Related topics

Source Resolver