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

NAudio now playing WMA files!

Nov 26, 2010 at 4:48 AM

Hi Mark,

Encouraged by the good results of Ogg support I managed to create another FileReader - this time for WMA.

Unlike NAudioOgg now the license for the WMA portion (not my entire LGPL utility) is MIT (or I can make it anything that fits NAudio's MS-PL) as I don't have dependencies on LGPL.

The class to look at is WMAFileReader.

The code is based on WMFSDK - I saw that you have some support for these COM interfaces, but I took some other classes that were actually working.

If you take the latest sources of Practice# (Beta 3.0) , I didn't prepare a binary, you can see a project named NAudioWMA. Inside there are Library and TestApp folders. The TestApp is a simple Console application that is similar to the test application I wrote for NAudioOgg.

Please feel free to incorporate these WMA sources into NAudio or at least provide them as a Demo application for other users.


Yuval Naveh

Nov 26, 2010 at 7:39 AM

brilliant, I will look into seeing if I can incorporate this. I want to get a new drop of NAudio out fairly shortly, and it would be nice if I can get this in in time,.


Nov 26, 2010 at 2:09 PM

Just one important technical note:

WMFSDK is implemented in COM which introduces some COM related issues - namely threading apartment models: STA and MTA 

If WMFSDK (and NAudioWMA) is used within a single threaded application (STA) like my demo console application then everything works fine.

HOWEVER, If there is one main STA (e.g. Windows Forms) and another worker thread where the COM interfaces are used then ALL calls to WMFSDK must go through the thread, in particular initialization.

Changing the main threading model (in Program) to MTA solved the problem, but Windows Forms is not supposed/does not properly to run in MTA.

To workaround this problem, I made my thread MTA (but kept the UI as STA) and moved ALL WMFSDK calls into my thread.

This solution works without any problems.

So to sum it up: There shouldn't be any cross-thread calls on WMFSDK, since COM does not like it.


Nov 26, 2010 at 2:12 PM

Yes, have run into similar issues with DirectSound in the past. I've checked in a bunch of your code, overwriting the original WMF interop code I had in there (which was only half-complete anyway).


Nov 27, 2010 at 12:42 AM

Hi Mark,

Took your latest sources and it works great. So my NAudioWMA project has been deprecated in my tool.

One minor documentation mistake I had in WMAFileReader.cs:

    /// NAudio reader for WMA Vorbis files

... I used my Ogg Vorbis reader as a base line for WMA...





Nov 29, 2010 at 5:06 PM

yes, I noticed that while copying it across but forgot to change it. I'll try to do that in a future checkin