In the uncompressed situation I know I need to read the wav header, pull out the number of channels, bits, and sample rate and work it out from there: (channels) * (bits) *
i have tested blew code would fail,file formats are like "\\ip\dir\*.wav'
public static class SoundInfo
{
[DllImport("winmm.dll")]
private static extern uint mciSendString
(
string command,
StringBuilder returnValue,
int returnLength,
IntPtr winHandle
);
public static int GetSoundLength(string fileName)
{
StringBuilder lengthBuf = new StringBuilder(32);
mciSendString(string.Format("open \"{0}\" type waveaudio alias wave", fileName), null, 0, IntPtr.Zero);
mciSendString("status wave length", lengthBuf, lengthBuf.Capacity, IntPtr.Zero);
mciSendString("close wave", null, 0, IntPtr.Zero);
int length = 0;
int.TryParse(lengthBuf.ToString(), out length);
return length;
}
}
while naudio works
public static int GetSoundLength(string fileName)
{
using (WaveFileReader wf = new WaveFileReader(fileName))
{
return (int)wf.TotalTime.TotalMilliseconds;
}
}`