2010-03-15 98 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文件夾。

相關問題