locked
MFCreateSourceReaderFromURL question

    Question

  • Dear all,

    I have a question about creating a source reader by using MFCreateSourceReaderFromURL.

    According to the document, we have to feed a string url to this function, but it is where the problem happens.

    My process follows:

    1. Get the StorageFile from FilePicker

    2. Pass the path or the name of the StorageFile object to this function, failed.

    3. Pass the URL by using URL.createObjectURL(xxx), failed.

    I know there is a sample code named :"Audio Clip" which demonstrates how to use MFCreateSourceReaderFromURL , but this is for Desktop version, not Metro.

    Does anyone know the solution about the first parameter of this function?

    thanks.

    Best regards,

    dupre

    Monday, May 7, 2012 10:43 AM

Answers

All replies

  • Hello Dupre,

    You should be able to get the "MFCreateSourceReaderFromURL" to work with the file picker. You need to make sure that the URL is formatted properly. I don't think you can use specific paths. Take a look at the Media Engine sample referenced below. If memory servers, this sample should show you how to interact between the ME and the file picker. I think that it should be the same with the source reader. Unfortunately I haven't verified this so if you run into any trouble please let me know and I will do what I can to help.

    Media engine native C++ playback sample
    http://code.msdn.microsoft.com/windowsapps/Media-Engine-Playback-ce1c82f0

    I hope this helps,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, May 8, 2012 1:07 AM
    Moderator
  • Dear James,

    Thanks for your replay and help, I will study the sample you mention.

    By the way, after thinking one night, I can describe my question more clearly.

    In fact, I have already used File Picker to select the file, and the file is in Music Library.

    I can get a StorageFile object, but how to transform it to the correct URL and put it into

    MFCreateSourceReaderFromURL is the main task.

    Please look at the function below,

    what is the suitable value for the first argument of MFCreateSourceReaderFromURL if I have a StorageFile object

    via File Picker ?

    HRESULT MFCreateSourceReaderFromURL(
      __in   LPCWSTR pwszURL,
      __in   IMFAttributes *pAttributes,
      __out  IMFSourceReader **ppSourceReader
    );

    Thanks.

    Best regards,

    dupre


    Tuesday, May 8, 2012 3:17 AM
  • Hello Dupre,

    Thanks for the clarification. AFAIK there is no easy way to open a IMFSourceReader from the file picker. You can't rely on the path that you receive from the file picker and must open the file via a IRandomAccessStream. In theory you can copy the data from the IRandomAccessStream into a IMFByteStream and then pass the IMFByteStream to MFCreateSourceReaderFromByteStream. Unfortunatley the few methods that allow you to create an IMFByteStream are marked as "desktop only" and likely can't be called from Metro style apps. That said you might try calling MFCreateTempFile. This API might work in the Metro environment. However I can't guarantee that it will work as expected.

    MFCreateSourceReaderFromByteStream
    http://msdn.microsoft.com/en-us/library/windows/desktop/dd388106(v=vs.85).aspx

    IRandomAccessStream
    http://msdn.microsoft.com/en-us/library/windows/apps/hh438400.aspx

    IMFByteStream
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms698720(v=vs.85).aspx

    MFCreateTempFile
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms695209(v=vs.85).aspx

    I hope this helps,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    • Marked as answer by dupre_tsai Wednesday, May 9, 2012 1:03 AM
    Tuesday, May 8, 2012 10:59 PM
    Moderator
  • Dear James,

    Thanks for your answer. In fact, I found an idea from the sample code you posted.

    The flow is like what you said. URL this way is not allowed, but fortunately, I can

    get a source reader by IMFByteStream. Thanks for your help.

    Best regards,

    dupre

    Wednesday, May 9, 2012 1:05 AM