Share via

Loading files for use with SourceReader

__AD__ 1 Reputation point
2022-04-01T09:56:53.443+00:00

Hi

I would like to use the Media Foundation SourceReader to read an audio file in a C++/winrt UWP application.

I use a FileOpenPicker to select an input file.

If the selected file exists inside the app package I can get the file path from the returned StorageFile and call MFCreateSourceReaderFromURL without problems.

If the file is located outside the app package then the call to MFCreateSourceReaderFromURL understandably results in a file permissions related error due to the locked-down nature of the UWP app.

I have seen the WASAPI example in the Windows universal samples which, given a StorageFile supplied by a FileOpenPicker:

  • calls OpenAsync on the StorageFile to get an IRandomAccessStream
  • calls MFCreateMFByteStreamOnStreamEx using the IRandomAccessStream
  • then calls MFCreateSourceReaderFromByteStream

Unfortunately I cannot make this work in a WinRT application. Firstly should this possible? If so are there any issues with the following pseudocode?:

IMFByteStream* byteStream = nullptr;
IRandomAccessStream stream = co_await file.OpenAsync(FileAccessMode::Read);
HRESULT hr = MFCreateMFByteStreamOnStreamEx(reinterpret_cast<IUnknown*>(&stream), &byteStream);

(file is a valid StorageFile provided by a FileOpenPicker)

The MFCreateMFByteStreamOnStreamEx results in:
Exception thrown at 0x00007FF8E7B0D6E8 (SHCore.dll) in XXX.exe: 0xC0000005: Access violation executing location 0x00007FF8E7B0D6E8.

Any insight very welcome

Many thanks

Developer technologies | Universal Windows Platform (UWP)
Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.