This project has moved. For the latest updates, please go here.

NAudio 1.7-alpha MediaFoundationReader

May 30, 2013 at 3:01 PM
Hi, I have the following code to play aac format:
            var reader = new MediaFoundationReader("d:\\Projects\\Samples\\aac.aac");

            var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback());
            var outDevice = CmbDevices.SelectedItem as OutDevice;
            if (outDevice != null)
                waveOut.DeviceNumber = outDevice.DeviceId;
            _waveOut = waveOut;
            _waveOut.PlaybackStopped += WaveOutOnPlaybackStopped;
But song playing only 1 second and after this StopPlayBack event is raised with Excaption. There no such problem with mp3 and Mp3FileReader. Also with WaveCallbackInfo.NewWindows() also everything works fine.

The exception is
Exception = {"Unable to cast COM object of type 'System.__ComObject' to interface type 'NAudio.MediaFoundation.IMFSourceReader'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{70AE66F2-C809-4E4F-8915-BDCB406B7993...
I found this post in StackOverflow:
but seems to me that it isn't the case because IMFSourceReader has ComImport with correct Guid.
Please help me to figure out with this issue.
Thanks, Roman
May 30, 2013 at 3:38 PM
I'd stay away from function callbacks if at all possible. Use WaveOutEvent if you want a background thread for audio playback.
May 31, 2013 at 7:21 AM
Edited May 31, 2013 at 7:22 AM
Thanks Mark,

So, if I understand you correct I need to do the following:

Use this:
var waveOut = new WaveOutEvent();
Instead of this:
var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback());
for background thread audio playback, right?
Jun 3, 2013 at 3:05 PM