I need to find a way to get the length of a WMA file without using any of the Windows Media Player(WMP) dlls. I found way to do it using WMP dlls, which you can see here, but due to another issue, I'd rather find a way where I don't have to use WMP.
One promising method that use NAudio and works with MP3s can be seen below:
double GetMediaDuration(string MediaFilename)
{
double duration = 0.0;
using (FileStream fs = File.OpenRead(MediaFilename))
{
Mp3Frame frame = Mp3Frame.LoadFromStream(fs);
if (frame != null)
{
_sampleFrequency = (uint)frame.SampleRate;
}
while (frame != null)
{
if (frame.ChannelMode == ChannelMode.Mono)
{
duration += (double)frame.SampleCount * 2.0 / (double)frame.SampleRate;
}
else
{
duration += (double)frame.SampleCount * 4.0 / (double)frame.SampleRate;
}
frame = Mp3Frame.LoadFromStream(fs);
}
}
return duration;
}
Does anyone know of a way to port this over to work with a WMA file instead?
I looked at the source for the WindowsMediaFormat project, but I could not find a WMAFrame class or anything that might obviously let me swap out a class in order to get this working for WMAs.
but everything else in the library is just definitions to allow access to the code in Microsoft’s Windows Media DLLs.
Doesn't this seem to suggest that it will be using the Windows Media Player dlls? – Spue