Same issue here. I tried using MediaFoundationReader to play FLAC files (I have Flac drivers installed - http://sourceforge.net/projects/mfflac/) - and the COMException brings the app down.
Here is the code I use in unit tests:
Here is the code I use in unit tests:
[Test]
public void FlacTestWithMediaFoundation()
{
string file = @"C:\Users\...\Track.flac";
byte[] buffer = new byte[65536];
using (var fileReader = new MediaFoundationReader(file))
{
int bytesRead;
do
{
bytesRead = fileReader.Read(buffer, 0, 65536);
Console.WriteLine("Read " + bytesRead);
} while (bytesRead > 0);
}
}
It reads the file to the end, then throws the exception: at NAudio.MediaFoundation.IMFSourceReader.ReadSample(Int32 dwStreamIndex, Int32 dwControlFlags, ref Int32 pdwActualStreamIndex, ref MF_SOURCE_READER_FLAG pdwStreamFlags, ref UInt64 pllTimestamp, ref IMFSample ppSample)
at NAudio.Wave.MediaFoundationReader.Read(Byte[] buffer, Int32 offset, Int32 count) in c:\src\naudio-current\NAudio\Wave\WaveStreams\MediaFoundationReader.cs: line 193
at MyApp.UnitTests.FlacTestWithMediaFoundation() in UnitTests.cs: line 60
It may be worth re-iterating that while the unit test simply fails, when I try running my app and playing a FLAC file, Windows shuts the app down, implying a non-recoverable error happens there even though I have exception handling code in the important places.