I’m trying to get the duration for an audio file in c#.
I got the following code to work on my local machine but when I deploy it to a windows server 2008 box it always returns a duration of 0 for .avi and .wav files.
WindowsMediaPlayerClass wmp = new WindowsMediaPlayerClass();
IWMPMedia mediaInfo = wmp.newMedia(filePath);
return mediaInfo.durationString
I have windows media player 11 installed on the server.
Any help would be most appreciated
I don’t have experience with “WindowsMediaPlayerClass”, but I have used TagLibSharp extensively, which is what I try to use for such things – it supports a pretty broad set of formats and that makes it’s API much more usable that the built-in support in .NET
http://developer.novell.com/wiki/index.php/TagLib_Sharp
Quite possibly simply using TagLibSharp will solve your problems.
(Note that taglibsharp is maintained by the banshee project, but is hosted @ novell for apparently historical reasons. I don’t know about the details, but that can make contacting the devs a little confusing)