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

Can't get wave file length on window xp

May 20, 2010 at 6:17 AM

I wrote a function to get file length of wave file. It's working on vista but then xp always throw exception at line "using (ResamplerDmoStream rso = new ResamplerDmoStream(reader, of))"

error detail:

/{System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {F447B69E-1884-4A7E-8055-346F74D6EDB3} failed due to the following error: 80040154.
   at NAudio.Dmo.Resampler..ctor()
   at NAudio.Wave.ResamplerDmoStream..ctor(IWaveProvider inputProvider, WaveFormat outputFormat)

static public TimeSpan GetFileLength(string filename)
        {
            try
            {
                if (File.Exists(filename))
                {
                    WaveFormat of = new WaveFormat(Convert.ToInt32(commonP.IniReadValue(Application.StartupPath + "\\" + commonP.iniPath, "Audio", "BIT_RATE")), Convert.ToInt32(commonP.IniReadValue(Application.StartupPath + "\\" + commonP.iniPath, "Audio", "CHANNEL")));
                    using (WaveFileReader reader = new WaveFileReader(filename))
                    {
                        using (ResamplerDmoStream rso = new ResamplerDmoStream(reader, of))
                        {
                            return rso.InputStream.TotalTime;
                        }
                    }
                }
            }
            catch(Exception ex)
            { }
            return new TimeSpan();
        }

Coordinator
May 20, 2010 at 7:19 AM
I'm afraid the ResamplerDMO is not available on Windows XP systems. You need to use the WaveFormatConversionStream instead
May 20, 2010 at 9:20 AM

Thanks Mark. I got it.