2010-03-15 100 views

回答

5

谷歌结果为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))); 
} 
+0

我在哪里可以找到Interop.WMPLib.dll?我可以使用上述文件而不是wmv吗?我只是引用了一个例子,我需要更多不同格式的文件。 – yeeen 2010-03-16 05:20:47

+0

我假设你可以使用这个任何文件格式安装的Windows媒体播放器版本将打开,但你必须测试它。我怀疑你会找到一个处理EVERY格式的库。 看看这个链接的底部,了解如何包装wmp.dll,如果它不在你的系统上... http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/ topic62074.aspx – gingerbreadboy 2010-03-16 09:15:38

0

你可以试试这个扩展方法。

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); 
    } 
} 
0

我希望下面的代码片段将帮助您:

using WMPLib; 
// ...your code here... 

var player = new WindowsMediaPlayer(); 
var clip = player.newMedia(filePath); 
Console.WriteLine(TimeSpan.FromSeconds(clip.duration)); 

,不要忘记添加的wmp.dll的参考,这将是 出现在System32文件夹。

相关问题