locked
Encounter a problem when Create a media source from a URL with media foundation. Hot to solve?

    Question

  • I want to create a media source from a URL with media foundation. And i follow the example given by MSDN, which is pasted below.  And i succeeds in  excuting "

    hr = pSourceResolver->CreateObjectFromURL " and  i think the program will work well, and connection is good, but then fail in executing " hr = pSource->QueryInterface(IID_PPV_ARGS(ppSource));",  then what is the problem? It seems that debug is hard here.

     

    
    
    //  Create a media source from a URL.
    HRESULT CreateMediaSource(PCWSTR sURL, IMFMediaSource **ppSource)
    {
        MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;
    
        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));
    
    done:
        SafeRelease(&pSourceResolver);
        SafeRelease(&pSource);
        return hr;
    }
    
    Wednesday, July 9, 2014 8:45 AM

All replies

  • Hi there, 

    so you are using sample from here: http://msdn.microsoft.com/en-us/library/windows/desktop/hh184779(v=vs.85).aspx , and what's returning value of code: 

    hr = pSource->QueryInterface(IID_PPV_ARGS(ppSource));?

    Regards,

    Jenny 

    Thursday, July 31, 2014 5:49 AM
  • hi,

         I just see your answer. I have solved this problem by defining IMFMediaSource *ppSource instead of IMFMediaSource **ppSource and by using hr = pSource->QueryInterface(IID_PPV_ARGS(&ppSource));    .

        And i leave the use scene for many days. 

       Regards,

    Alan 

    Tuesday, August 19, 2014 1:02 AM