Any library in C# that allows me to do that?
Asked
Active
Viewed 4,279 times
1
-
Does it matter? For eg wmv... – yeeen Mar 15 '10 at 09:09
-
1Here's a related question: http://stackoverflow.com/questions/1256841/c-get-video-file-duration-from-metadata – Peter Lillevold Mar 15 '10 at 09:10
-
Because tt qn don't hv a sol to it! And i don't hv LoaderLock exception... I managed to get the right way to use Direct X after figuring out tt i need the SDK for it. Below got another sol, i wonder if it is better than Direct X? – yeeen Mar 16 '10 at 05:23
3 Answers
4
google result for http://johndyer.name/post/2005/07/22/Retreiving-the-duration-of-a-WMV-in-C.aspx
using WMPLib; // this file is called Interop.WMPLib.dll
WindowsMediaPlayerClass wmp = new WindowsMediaPlayerClass();
IWMPMedia mediaInfo = wmp.newMedia("myfile.wmv");
// write duration
Console.WriteLine("Duration = " + mediaInfo.duration);
// write named attributes
for (int i=0; i<mediaInfo.attributeCount; i++)
{
Console.WriteLine(mediaInfo.getAttributeName(i) + " = " + mediaInfo.getItemInfo(mediaInfo.getAttributeName(i)) );
}

gingerbreadboy
- 7,386
- 5
- 36
- 62
-
Where do I find Interop.WMPLib.dll? Can I use the above for files other than wmv? I was just quoting an eg, i need more files of different format. – yeeen Mar 16 '10 at 05:20
-
I'd assume you could use this for any file format your installed version of windows media player will open, but you'd have to test it. I doubt you'll find a library which will handle EVERY format. Look at the bottom of this link for instruction on how to wrap wmp.dll if it's not on your system... http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic62074.aspx – gingerbreadboy Mar 16 '10 at 09:15
0
I hope following code snippet will help you :
using WMPLib;
// ...your code here...
var player = new WindowsMediaPlayer();
var clip = player.newMedia(filePath);
Console.WriteLine(TimeSpan.FromSeconds(clip.duration));
and don't forget to add the reference of
wmp.dll
which will be present inSystem32
folder.

Rish
- 1,303
- 9
- 22
0
You can try this Extension method.
using Shell32;
public static class Extension
{
public static string GetLength(this FileInfo info)
{
var shell = new ShellClass();
var folder = shell.NameSpace(info.DirectoryName);
var item = folder.ParseName(info.Name);
return folder.GetDetailsOf(item, 27);
}
}

Sun
- 2,110
- 2
- 21
- 28